123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- /*
- Photo.js
- Author: tobychui
- This is a complete rewrite of the legacy Photo module for ArozOS
- */
- let photoList = [];
- let prePhoto = "";
- let nextPhoto = "";
- let currentModel = "";
- function scrollbarVisable(){
- return $("body")[0].scrollHeight > $("body").height();
- }
- function getImageWidth(){
- let boxCount = 4;
- if (window.innerWidth < 500) {
- boxCount = 3;
- } else if (window.innerWidth < 800) {
- boxCount = 4;
- } else if (window.innerWidth < 1200) {
- boxCount = 6;
- }else if (window.innerWidth < 1600){
- boxCount = 8;
- } else {
- boxCount = 10;
- }
- let offsets = 2;
- if (scrollbarVisable()){
- offsets = offsets * 1.2;
- }
- return $("#viewbox").width() / boxCount - offsets;
- }
- function updateImageSizes(){
- let newImageWidth = getImageWidth();
- //Updates all the size of the images
- $(".imagecard").css({
- width: newImageWidth,
- height: newImageWidth
- });
- }
- function closeSideMenu(){
- $('#menu').toggle('fast', function(){
- updateImageSizes();
- });
-
- }
- function extractFolderName(folderpath){
- return folderpath.split("/").pop();
- }
- function initSelectedModelValue(){
- ao_module_agirun("Photo/backend/modelSelector.js",{
- }, function(data){
- currentModel = data;
- $("#selectedModel").dropdown("set selected", data);
- })
- }
- function updateSelectedModel(nnnm){
- if (nnnm != ""){
- ao_module_agirun("Photo/backend/modelSelector.js",{
- set: true,
- model: nnnm
- }, function(data){
- console.log("Update model status: ", data);
- $("#modelUpdated").slideDown("fast").delay(3000).slideUp('fast');
- })
- }
- }
- function settingObject(){
- return {
- excludeDirs: ["Manga","thumbnail"],
- init(){
- this.loadExcludeList();
- $('#newexc input').off("keypress").on("keypress",function (e) {
- if (e.which == 13) {
- addDir($('#newexc input'));
- }
- });
-
- $(".ui.dropdown").dropdown();
- initSelectedModelValue();
- },
- addDir(element){
- var dir = $(element).parent().find("input").val();
- $("#newexc").removeClass("error");
- for (var i = 0; i < this.excludeDirs.length; i++){
- if (this.excludeDirs[i] == dir){
- //Already exists
- $("#newexc").addClass("error");
- return;
- }
- }
- this.excludeDirs.push(dir);
- $('#newexc input').val("");
- },
- removeDir(filepath){
- //Pop the given filepath from list
- var newExcludeDirs = [];
- for ( var i = 0; i < this.excludeDirs.length; i++){
- var thisExcludeDir = this.excludeDirs[i];
- if (thisExcludeDir != filepath){
- newExcludeDirs.push(thisExcludeDir);
- }
- }
- this.excludeDirs = newExcludeDirs;
- },
- loadExcludeList(){
- $("#noexcRecords").hide();
- fetch(ao_root + "system/ajgi/interface?script=Photo/backend/exclude.js", {
- method: 'POST',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
-
- })
- }).then(resp => {
- resp.json().then(data => {
- console.log(data);
- this.excludeDirs = data;
- if (data.length == 0){
- $("#noexcRecords").show();
- }
- })
- });
- },
- save(){
- fetch(ao_root + "system/ajgi/interface?script=Photo/backend/exclude.js", {
- method: 'POST',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- "set":true,
- "folders": this.excludeDirs
- })
- }).then(resp => {
- resp.json().then(data => {
- })
- });
- }
- }
- }
- function photoListObject() {
- return {
- // data
- pathWildcard: "user:/Photo/*",
- currentPath: "user:/Photo",
- renderSize: 200,
- vroots: [],
- images: [],
- folders: [],
- tags: [],
-
- // init
- init() {
- this.getFolderInfo();
- this.getRootInfo();
- this.renderSize = getImageWidth();
- updateImageSizes();
- },
-
- updateRenderingPath(newPath){
- this.currentPath = JSON.parse(JSON.stringify(newPath));
- this.pathWildcard = newPath + '/*';
- if (this.pathWildcard.split("/").length == 3){
- //Root path already
- $("#parentFolderButton").hide();
- }else{
- $("#parentFolderButton").show();
- }
- this.getFolderInfo();
- },
- parentFolder(){
- var parentPath = JSON.parse(JSON.stringify(this.currentPath));
- parentPath = parentPath.split("/");
- parentPath.pop();
- this.currentPath = parentPath.join("/");
- this.updateRenderingPath( this.currentPath);
- },
- getFolderInfo() {
- fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listFolder.js", {
- method: 'POST',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- "folder": this.pathWildcard
- })
- }).then(resp => {
- resp.json().then(data => {
- console.log(data);
- this.folders = data[0];
- this.images = data[1];
- if (this.images.length == 0){
- $("#noimg").show();
- }else{
- $("#noimg").hide();
- }
- if (this.folders.length == 0){
- $("#nosubfolder").show();
- }else{
- $("#nosubfolder").hide();
- }
- console.log(this.folders);
-
- });
- });
- this.getTags();
- },
- getRootInfo() {
- fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listRoots.js", {
- method: 'POST',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({})
- }).then(resp => {
- resp.json().then(data => {
- this.vroots = data;
- });
- })
- },
- getTags(){
- fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listTags.js", {
- method: 'POST',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- "vroot": this.currentPath
- })
- }).then(resp => {
- resp.json().then(data => {
- this.tags = data;
- });
- });
- }
- }
- }
- function renderImageList(object){
- var fd = $(object).attr("filedata");
- fd = JSON.parse(decodeURIComponent(fd));
- console.log(fd);
-
- }
- function ShowModal(){
- $('.ui.modal.viewer').modal({
- onHide: function(){
- ao_module_setWindowTitle("Photo");
- setTimeout(function(){
- $("#fullImage").attr("src","img/loading.png");
- }, 300)
- }
- }).modal('show');
- }
- function showImage(object){
- var fd = JSON.parse(decodeURIComponent($(object).attr("filedata")));
- $("#fullImage").attr('src', "../media?file=" + fd.filepath);
- var nextCard = $(object).next(".imagecard");
- var prevCard = $(object).prev(".imagecard");
- if (nextCard.length > 0){
- nextPhoto = nextCard[0];
- }else{
- nextPhoto = null;
- }
- if (prevCard.length > 0){
- prePhoto = prevCard[0];
- }else{
- prePhoto = null;
- }
- ao_module_setWindowTitle("Photo - " + fd.filename);
- }
- $(document).on("keydown", function(e){
- if (e.keyCode == 37){
- //Left
- if (prePhoto != null){
- //$('.ui.modal').modal("hide");
- showImage(prePhoto);
- }
-
- }else if (e.keyCode == 39){
- //Right
- if (nextPhoto != null){
- //$('.ui.modal').modal("hide");
- showImage(nextPhoto);
- }
-
- }
- })
- function showSetting(){
- $('.ui.modal.setting').modal('show');
- }
- function rescan(object){
- var originalContent = $(object).html();
- $(object).addClass("disabled");
- $(object).html(`<i class="ui spinner loading icon"></i> Analysing`);
- ao_module_agirun("Photo/backend/classify.js", {
- }, function(data){
- //Done
- $(object).removeClass("disabled");
- $(object).html(`<i class="ui green checkmark icon"></i> Done`);
- setTimeout(function(){
- $(object).html(originalContent);
- }, 3000);
-
- });
- }
|