photo.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. Photo.js
  3. Author: tobychui
  4. This is a complete rewrite of the legacy Photo module for ArozOS
  5. */
  6. let photoList = [];
  7. function scrollbarVisable(){
  8. return $("body")[0].scrollHeight > $("body").height();
  9. }
  10. function getImageWidth(){
  11. let boxCount = 4;
  12. if (window.innerWidth < 500) {
  13. boxCount = 3;
  14. } else if (window.innerWidth < 800) {
  15. boxCount = 4;
  16. } else if (window.innerWidth < 1200) {
  17. boxCount = 6;
  18. }else if (window.innerWidth < 1600){
  19. boxCount = 8;
  20. } else {
  21. boxCount = 10;
  22. }
  23. let offsets = 2;
  24. if (scrollbarVisable()){
  25. offsets = offsets * 1.2;
  26. }
  27. return $("#viewbox").width() / boxCount - offsets;
  28. }
  29. function updateImageSizes(){
  30. let newImageWidth = getImageWidth();
  31. //Updates all the size of the images
  32. $(".imagecard").css({
  33. width: newImageWidth,
  34. height: newImageWidth
  35. });
  36. }
  37. function closeSideMenu(){
  38. $('#menu').toggle('fast', function(){
  39. updateImageSizes();
  40. });
  41. }
  42. function extractFolderName(folderpath){
  43. return folderpath.split("/").pop();
  44. }
  45. function photoListObject() {
  46. return {
  47. // data
  48. pathWildcard: "user:/Photo/*",
  49. currentPath: "user:/Photo",
  50. renderSize: 200,
  51. vroots: [],
  52. images: [],
  53. folders: [],
  54. tags: [],
  55. // init
  56. init() {
  57. this.getFolderInfo();
  58. this.getRootInfo();
  59. this.renderSize = getImageWidth();
  60. updateImageSizes();
  61. },
  62. updateRenderingPath(newPath){
  63. this.currentPath = JSON.parse(JSON.stringify(newPath));
  64. this.pathWildcard = newPath + '/*';
  65. if (this.pathWildcard.split("/").length == 3){
  66. //Root path already
  67. $("#parentFolderButton").hide();
  68. }else{
  69. $("#parentFolderButton").show();
  70. }
  71. this.getFolderInfo();
  72. },
  73. parentFolder(){
  74. var parentPath = JSON.parse(JSON.stringify(this.currentPath));
  75. parentPath = parentPath.split("/");
  76. parentPath.pop();
  77. this.currentPath = parentPath.join("/");
  78. this.updateRenderingPath( this.currentPath);
  79. },
  80. getFolderInfo() {
  81. fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listFolder.js", {
  82. method: 'POST',
  83. cache: 'no-cache',
  84. headers: {
  85. 'Content-Type': 'application/json'
  86. },
  87. body: JSON.stringify({
  88. "folder": this.pathWildcard
  89. })
  90. }).then(resp => {
  91. resp.json().then(data => {
  92. console.log(data);
  93. this.folders = data[0];
  94. this.images = data[1];
  95. if (this.images.length == 0){
  96. $("#noimg").show();
  97. }else{
  98. $("#noimg").hide();
  99. }
  100. if (this.folders.length == 0){
  101. $("#nosubfolder").show();
  102. }else{
  103. $("#nosubfolder").hide();
  104. }
  105. console.log(this.folders);
  106. });
  107. });
  108. this.getTags();
  109. },
  110. getRootInfo() {
  111. fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listRoots.js", {
  112. method: 'POST',
  113. cache: 'no-cache',
  114. headers: {
  115. 'Content-Type': 'application/json'
  116. },
  117. body: JSON.stringify({})
  118. }).then(resp => {
  119. resp.json().then(data => {
  120. this.vroots = data;
  121. });
  122. })
  123. },
  124. getTags(){
  125. fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listTags.js", {
  126. method: 'POST',
  127. cache: 'no-cache',
  128. headers: {
  129. 'Content-Type': 'application/json'
  130. },
  131. body: JSON.stringify({
  132. "vroot": this.currentPath
  133. })
  134. }).then(resp => {
  135. resp.json().then(data => {
  136. this.tags = data;
  137. });
  138. });
  139. }
  140. }
  141. }
  142. function renderImageList(object){
  143. var fd = $(object).attr("filedata");
  144. fd = JSON.parse(decodeURIComponent(fd));
  145. console.log(fd);
  146. }
  147. function ShowModal(){
  148. $('.ui.modal').modal({
  149. onHide: function(){
  150. ao_module_setWindowTitle("Photo");
  151. }
  152. }).modal('show');
  153. }
  154. function showImage(object){
  155. var fd = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  156. console.log(fd);
  157. $("#fullImage").attr('src', "../media?file=" + fd.filepath);
  158. var nextCard = $(object).next(".imagecard");
  159. var prevCard = $(object).prev(".imagecard");
  160. if (nextCard.length > 0){
  161. }
  162. if (prevCard.length > 0){
  163. }
  164. ao_module_setWindowTitle("Photo - " + fd.filename);
  165. console.log(nextCard, prevCard);
  166. }
  167. function rescan(object){
  168. var originalContent = $(object).html();
  169. $(object).html(`<i class="ui spinner loading icon"></i> Analysing`);
  170. ao_module_agirun("Photo/backend/classify.js", {
  171. }, function(data){
  172. //Done
  173. $(object).html(`<i class="ui green checkmark icon"></i> Done`);
  174. setTimeout(function(){
  175. $(object).html(originalContent);
  176. }, 3000);
  177. });
  178. }