From 3b2f889d631a66765b07640c817d39574171ebe9 Mon Sep 17 00:00:00 2001 From: "phat.truong" Date: Wed, 22 Mar 2023 18:27:01 +0700 Subject: [PATCH 1/8] Duplicate database --- .../wwwroot/mix-app/js/app-portal.min.js | 7499 ++++++++--------- .../_layout-portal-modals/view.html | 2 +- .../app-portal/pages/mix-database/list.html | 2 +- .../Controllers/MixDatabaseController.cs | 17 +- .../ViewModels/MixDatabaseViewModel.cs | 13 +- 5 files changed, 3738 insertions(+), 3795 deletions(-) diff --git a/src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js b/src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js index 2476f7d0b..9840f2ae2 100644 --- a/src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js +++ b/src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js @@ -1,4 +1,4 @@ -/* Sat Mar 18 2023 13:27:39 GMT+0700 (Indochina Time) */"use strict"; +/* Wed Mar 22 2023 18:16:31 GMT+0700 (Indochina Time) */"use strict"; var app = angular.module("MixPortal", [ "angularCroppie", "ui.bootstrap", @@ -492,118 +492,6 @@ app.factory("MixApplicationRestService", [ }, ]); -"use strict"; -app.controller("AuditLogController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$location", - "$routeParams", - "AuthService", - "AuditLogRestService", - function ( - $scope, - $rootScope, - ngAppSettings, - $location, - $routeParams, - authService, - service - ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - service - ); - BaseHub.call(this, $scope); - authService.fillAuthData(); - $scope.request.status = null; - $scope.messages = []; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - - $scope.connect = () => { - $scope.startConnection( - "log-stream-hub", - authService.authentication.accessToken, - (err) => { - if ( - authService.authentication.refreshToken && - err.message.indexOf("401") >= 0 - ) { - authService.refreshToken().then(async () => { - $scope.startConnection( - "log-stream-hub", - authService.authentication.accessToken - ); - }); - } - } - ); - }; - $scope.receiveMessage = function (msg) { - switch (msg.action) { - case "MyConnection": - $scope.hubRequest.from = msg.data; - $scope.$apply(); - break; - case "NewMessage": - $scope.newMessage(msg); - - break; - } - }; - $scope.newMessage = function (msg) { - msg.style = $scope.getMessageType(msg.type); - if (msg.data) { - msg.data = JSON.parse(msg.data); - } - $scope.messages.push(msg); - $scope.$apply(); - - setTimeout(() => { - $("body,html").animate( - { - scrollTop: $("#log-stream-container").height(), // Scroll to top of body - }, - 500 - ); - }, 200); - }; - $scope.getMessageType = function (type) { - switch (type) { - case "Success": - return "success"; - case "Error": - return "danger"; - case "Warning": - return "warning"; - case "Info": - return "info"; - default: - return "default"; - } - }; - $scope.view = function (item) { - $rootScope.preview("object", item, null, "modal-lg"); - }; - }, -]); - -"use strict"; -app.factory("AuditLogRestService", [ - "BaseRestService", - function (baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("audit-log"); - return serviceFactory; - }, -]); - "use strict"; app.controller("ConfigurationController", [ "$scope", @@ -796,203 +684,114 @@ app.factory("CultureService", [ ]); "use strict"; -app.controller("CustomerController", [ +app.controller("AuditLogController", [ "$scope", "$rootScope", "ngAppSettings", - "$routeParams", - "$timeout", "$location", - "CustomerServices", + "$routeParams", + "AuthService", + "AuditLogRestService", function ( $scope, $rootScope, ngAppSettings, - $routeParams, - $timeout, $location, - customerServices + $routeParams, + authService, + service ) { - $scope.request = angular.copy(ngAppSettings.request); - $scope.request.contentStatuses = ["Active"]; - $scope.request.status = "0"; - $scope.activedCustomer = null; - $scope.relatedCustomers = []; - $rootScope.isBusy = false; - $scope.data = { - pageIndex: 0, - pageSize: 1, - totalItems: 0, - }; - $scope.errors = []; - - $scope.range = function (max) { - var input = []; - for (var i = 1; i <= max; i += 1) input.push(i); - return input; - }; + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + service + ); + BaseHub.call(this, $scope); + authService.fillAuthData(); + $scope.request.status = null; + $scope.messages = []; + $scope.canDrag = + $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.loadCustomer = async function () { - $rootScope.isBusy = true; - var id = $routeParams.id; - var response = await customerServices.getCustomer(id, "portal"); - if (response.success) { - $scope.activedCustomer = response.data; - $rootScope.initEditor(); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.loadCustomers = async function (pageIndex) { - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } - if ($scope.request.fromDate !== null) { - var d = new Date($scope.request.fromDate); - $scope.request.fromDate = d.toISOString(); - } - if ($scope.request.toDate !== null) { - var d = new Date($scope.request.toDate); - $scope.request.toDate = d.toISOString(); - } - var resp = await customerServices.getCustomers($scope.request); - if (resp && resp.success) { - $scope.data = resp.data; - //$("html, body").animate({ "scrollTop": "0px" }, 500); - $.each($scope.data.items, function (i, customer) { - $.each($scope.activedCustomers, function (i, e) { - if (e.customerId === customer.id) { - customer.isHidden = true; - } - }); - }); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.connect = () => { + $scope.startConnection( + "log-stream-hub", + authService.authentication.accessToken, + (err) => { + if ( + authService.authentication.refreshToken && + err.message.indexOf("401") >= 0 + ) { + authService.refreshToken().then(async () => { + $scope.startConnection( + "log-stream-hub", + authService.authentication.accessToken + ); + }); + } } - $scope.$apply(); - } - }; - - $scope.removeCustomer = function (id) { - $rootScope.showConfirm( - $scope, - "removeCustomerConfirmed", - [id], - null, - "Remove Customer", - "Deleted data will not able to recover, are you sure you want to delete this item?" ); }; + $scope.receiveMessage = function (msg) { + switch (msg.action) { + case "MyConnection": + $scope.hubRequest.from = msg.data; + $scope.$apply(); + break; + case "NewMessage": + $scope.newMessage(msg); - $scope.removeCustomerConfirmed = async function (id) { - var result = await customerServices.removeCustomer(id); - if (result.success) { - $rootScope.showMessage("success", "success"); - $scope.loadCustomers(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); + break; } }; + $scope.newMessage = function (msg) { + msg.style = $scope.getMessageType(msg.type); + if (msg.data) { + msg.data = JSON.parse(msg.data); + } + $scope.messages.push(msg); + $scope.$apply(); - $scope.saveCustomer = async function (customer) { - customer.content = $(".editor-content").val(); - var resp = await customerServices.saveCustomer(customer); - if (resp && resp.success) { - $scope.activedCustomer = resp.data; - $rootScope.showMessage("Update successfully!", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - //$location.path('/admin/customer/details/' + resp.data.id); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $scope.$apply(); + setTimeout(() => { + $("body,html").animate( + { + scrollTop: $("#log-stream-container").height(), // Scroll to top of body + }, + 500 + ); + }, 200); + }; + $scope.getMessageType = function (type) { + switch (type) { + case "Success": + return "success"; + case "Error": + return "danger"; + case "Warning": + return "warning"; + case "Info": + return "info"; + default: + return "default"; } }; + $scope.view = function (item) { + $rootScope.preview("object", item, null, "modal-lg"); + }; }, ]); "use strict"; -app.factory("CustomerServices", [ - "$http", - "$rootScope", - "ApiService", - "CommonService", - function ($http, $rootScope, apiService, commonService) { - //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; - - var customersServiceFactory = {}; - - var settings = $rootScope.globalSettings; - - var _getCustomer = async function (id, type) { - var apiUrl = "/queen-beauty/customer/"; - var url = apiUrl + "details/" + type; - if (id) { - url += "/" + id; - } - var req = { - method: "GET", - url: url, - }; - return await apiService.sendRequest(req); - }; - - var _initCustomer = async function (type) { - var apiUrl = "/queen-beauty/customer/"; - var req = { - method: "GET", - url: apiUrl + "init/" + type, - }; - return await apiService.sendRequest(req); - }; - - var _getCustomers = async function (request) { - var apiUrl = "/queen-beauty/customer/"; - var req = { - method: "POST", - url: apiUrl + "list", - data: JSON.stringify(request), - }; - - return await apiService.sendRequest(req); - }; - - var _removeCustomer = async function (id) { - var apiUrl = "/queen-beauty/customer/"; - var req = { - method: "GET", - url: apiUrl + "delete/" + id, - }; - return await apiService.sendRequest(req); - }; - - var _saveCustomer = async function (customer) { - var apiUrl = "/queen-beauty/customer/"; - var req = { - method: "POST", - url: apiUrl + "save", - data: JSON.stringify(customer), - }; - return await apiService.sendRequest(req); - }; - - customersServiceFactory.getCustomer = _getCustomer; - customersServiceFactory.initCustomer = _initCustomer; - customersServiceFactory.getCustomers = _getCustomers; - customersServiceFactory.removeCustomer = _removeCustomer; - customersServiceFactory.saveCustomer = _saveCustomer; - return customersServiceFactory; +app.factory("AuditLogRestService", [ + "BaseRestService", + function (baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("audit-log"); + return serviceFactory; }, ]); @@ -1088,62 +887,14 @@ app.factory("DashboardServices", [ ]); "use strict"; -app.controller("DomainController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$location", - "$routeParams", - "DomainRestService", - function ( - $scope, - $rootScope, - ngAppSettings, - $location, - $routeParams, - service - ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - service - ); - $scope.request.columns = [ - "id", - "displayName", - "host", - "createdDateTime", - "createdBy", - ]; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - }, -]); - -"use strict"; -app.factory("DomainRestService", [ - "BaseRestService", - function (baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("mix-domain"); - return serviceFactory; - }, -]); - -"use strict"; -app.controller("FileController", [ +app.controller("CustomerController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$timeout", "$location", - "AuthService", - "FileServices", + "CustomerServices", function ( $scope, $rootScope, @@ -1151,23 +902,13 @@ app.controller("FileController", [ $routeParams, $timeout, $location, - authService, - fileServices + customerServices ) { - $scope.request = { - pageSize: "10", - pageIndex: 0, - status: "Published", - orderBy: "CreatedDateTime", - direction: "Desc", - fromDate: null, - toDate: null, - keyword: "", - key: "", - }; - - $scope.activedFile = null; - $scope.relatedFiles = []; + $scope.request = angular.copy(ngAppSettings.request); + $scope.request.contentStatuses = ["Active"]; + $scope.request.status = "0"; + $scope.activedCustomer = null; + $scope.relatedCustomers = []; $rootScope.isBusy = false; $scope.data = { pageIndex: 0, @@ -1181,25 +922,14 @@ app.controller("FileController", [ for (var i = 1; i <= max; i += 1) input.push(i); return input; }; - $scope.loadPage = async function (folder) { - if (folder) { - $scope.request.folder += $scope.request.folder !== "" ? "/" : ""; - $scope.request.folder += folder; - } - $location.url( - "/admin/file/list?folder=" + encodeURIComponent($scope.request.folder) - ); - }; - $scope.loadFile = async function () { - $rootScope.isBusy = true; - $scope.listUrl = "/admin/file/list?folder/" + $routeParams.folder; + + $scope.loadCustomer = async function () { $rootScope.isBusy = true; - var response = await fileServices.getFile( - $routeParams.folder, - $routeParams.filename - ); + var id = $routeParams.id; + var response = await customerServices.getCustomer(id, "portal"); if (response.success) { - $scope.activedFile = response.data; + $scope.activedCustomer = response.data; + $rootScope.initEditor(); $rootScope.isBusy = false; $scope.$apply(); } else { @@ -1208,34 +938,26 @@ app.controller("FileController", [ $scope.$apply(); } }; - $scope.loadFiles = async function (folder) { - if (folder) { - $scope.request.folder += - $scope.request.folder !== "" - ? "MixContent/StaticFiles" - : "MixContent/StaticFiles"; - $scope.request.folder += folder; - } else { - $scope.request.folder = $routeParams.folder - ? $routeParams.folder - : "MixContent/StaticFiles"; + $scope.loadCustomers = async function (pageIndex) { + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; } - if ($routeParams.folder) { - $scope.backUrl = - "/admin/file/list?folder=" + - $routeParams.folder.substring( - 0, - $routeParams.folder.lastIndexOf("/") - ); + if ($scope.request.fromDate !== null) { + var d = new Date($scope.request.fromDate); + $scope.request.fromDate = d.toISOString(); } - $rootScope.isBusy = true; - var resp = await fileServices.getFiles($scope.request); + if ($scope.request.toDate !== null) { + var d = new Date($scope.request.toDate); + $scope.request.toDate = d.toISOString(); + } + var resp = await customerServices.getCustomers($scope.request); if (resp && resp.success) { $scope.data = resp.data; - $.each($scope.data.items, function (i, file) { - $.each($scope.activedFiles, function (i, e) { - if (e.fileId === file.id) { - file.isHidden = true; + //$("html, body").animate({ "scrollTop": "0px" }, 500); + $.each($scope.data.items, function (i, customer) { + $.each($scope.activedCustomers, function (i, e) { + if (e.customerId === customer.id) { + customer.isHidden = true; } }); }); @@ -1245,62 +967,71 @@ app.controller("FileController", [ if (resp) { $rootScope.showErrors(resp.errors); } - $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.removeFile = async function (id) { - if (confirm("Are you sure!")) { - $rootScope.isBusy = true; - var resp = await fileServices.removeFile(id); - if (resp && resp.success) { - $scope.loadFiles(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } + $scope.removeCustomer = function (id) { + $rootScope.showConfirm( + $scope, + "removeCustomerConfirmed", + [id], + null, + "Remove Customer", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + $scope.removeCustomerConfirmed = async function (id) { + var result = await customerServices.removeCustomer(id); + if (result.success) { + $rootScope.showMessage("success", "success"); + $scope.loadCustomers(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); } }; - $scope.saveFile = async function (file) { - $rootScope.isBusy = true; - var resp = await fileServices.saveFile(file); + $scope.saveCustomer = async function (customer) { + customer.content = $(".editor-content").val(); + var resp = await customerServices.saveCustomer(customer); if (resp && resp.success) { - $scope.activedFile = resp.data; + $scope.activedCustomer = resp.data; $rootScope.showMessage("Update successfully!", "success"); $rootScope.isBusy = false; $scope.$apply(); + //$location.path('/admin/customer/details/' + resp.data.id); } else { if (resp) { $rootScope.showErrors(resp.errors); } - $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.updateTemplateContent = function (content) { - $scope.activedFile.content = content; - }; }, ]); "use strict"; -app.factory("FileServices", [ +app.factory("CustomerServices", [ "$http", "$rootScope", "ApiService", "CommonService", - "BaseRestService", - function ($http, $rootScope, apiService, commonService, baseService) { - var filesServiceFactory = angular.copy(baseService); - filesServiceFactory.initService("/rest", "mix-storage/file-system", true); - var _getFile = async function (folder, filename) { - var url = - this.prefixUrl + "/details?folder=" + folder + "&filename=" + filename; + function ($http, $rootScope, apiService, commonService) { + //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; + + var customersServiceFactory = {}; + + var settings = $rootScope.globalSettings; + + var _getCustomer = async function (id, type) { + var apiUrl = "/queen-beauty/customer/"; + var url = apiUrl + "details/" + type; + if (id) { + url += "/" + id; + } var req = { method: "GET", url: url, @@ -1308,129 +1039,103 @@ app.factory("FileServices", [ return await apiService.sendRequest(req); }; - var _initFile = async function (type) { + var _initCustomer = async function (type) { + var apiUrl = "/queen-beauty/customer/"; var req = { method: "GET", - url: this.prefixUrl + "/init/" + type, + url: apiUrl + "init/" + type, }; return await apiService.sendRequest(req); }; - var _getFiles = async function (request) { - var url = this.prefixUrl; - var data = filesServiceFactory.parseQuery(request); - if (data) { - url += "?"; - url = url.concat(data); - } + var _getCustomers = async function (request) { + var apiUrl = "/queen-beauty/customer/"; var req = { - method: "GET", - url: url, + method: "POST", + url: apiUrl + "list", data: JSON.stringify(request), }; + return await apiService.sendRequest(req); }; - var _removeFile = async function (fullPath) { + var _removeCustomer = async function (id) { + var apiUrl = "/queen-beauty/customer/"; var req = { - method: "DELETE", - url: this.prefixUrl + "/delete/?fullPath=" + fullPath, + method: "GET", + url: apiUrl + "delete/" + id, }; return await apiService.sendRequest(req); }; - var _saveFile = async function (file) { + var _saveCustomer = async function (customer) { + var apiUrl = "/queen-beauty/customer/"; var req = { method: "POST", - url: this.prefixUrl + "/save", - data: JSON.stringify(file), + url: apiUrl + "save", + data: JSON.stringify(customer), }; return await apiService.sendRequest(req); }; - var _uploadFile = async function (file, folder) { - var apiUrl = this.prefixUrl + "/upload-file"; - var fd = new FormData(); - fd.append("folder", folder); - fd.append("file", file); - return await filesServiceFactory.ajaxSubmitForm(fd, apiUrl); - }; - - var _extractFile = async function (file, folder) { - var apiUrl = this.prefixUrl + "/extract-file"; - var fd = new FormData(); - fd.append("folder", folder); - fd.append("file", file); - return await filesServiceFactory.ajaxSubmitForm(fd, apiUrl); - }; - filesServiceFactory.getFile = _getFile; - filesServiceFactory.initFile = _initFile; - filesServiceFactory.getFiles = _getFiles; - filesServiceFactory.removeFile = _removeFile; - filesServiceFactory.saveFile = _saveFile; - filesServiceFactory.uploadFile = _uploadFile; - filesServiceFactory.extractFile = _extractFile; - return filesServiceFactory; + customersServiceFactory.getCustomer = _getCustomer; + customersServiceFactory.initCustomer = _initCustomer; + customersServiceFactory.getCustomers = _getCustomers; + customersServiceFactory.removeCustomer = _removeCustomer; + customersServiceFactory.saveCustomer = _saveCustomer; + return customersServiceFactory; }, ]); "use strict"; -app.controller("ImportFileController", [ +app.controller("DomainController", [ "$scope", "$rootScope", - "ImportFileServices", - "TranslatorService", - "AppSettingsService", + "ngAppSettings", + "$location", + "$routeParams", + "DomainRestService", function ( $scope, $rootScope, - service, - translatorService, - AppSettingsService + ngAppSettings, + $location, + $routeParams, + service ) { - $scope.saveImportFile = async function () { - $rootScope.isBusy = true; - var form = document.getElementById("frm-import"); - var frm = new FormData(); - frm.append("assets", form["assets"].files[0]); - var response = await service.saveImportFile(frm); - if (response.success) { - $scope.viewmodel = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + service + ); + $scope.request.columns = [ + "id", + "displayName", + "host", + "createdDateTime", + "createdBy", + ]; + $scope.canDrag = + $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; }, ]); "use strict"; -app.factory("ImportFileServices", [ - "$rootScope", - "BaseService", - function ($rootScope, baseService) { - //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; - - var serviceFactory = {}; - - var settings = $rootScope.globalSettings; +app.factory("DomainRestService", [ + "BaseRestService", + function (baseService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("portal", true); - var _saveImportFile = async function (frm) { - var apiUrl = this.prefixUrl + "/" + settings.lang + "/import"; - return await this.ajaxSubmitForm(frm, apiUrl); - }; - - serviceFactory.saveImportFile = _saveImportFile; + serviceFactory.init("mix-domain"); return serviceFactory; }, ]); "use strict"; -app.controller("JsonDataController", [ +app.controller("FileController", [ "$scope", "$rootScope", "ngAppSettings", @@ -1438,7 +1143,7 @@ app.controller("JsonDataController", [ "$timeout", "$location", "AuthService", - "JsonDataService", + "FileServices", function ( $scope, $rootScope, @@ -1447,7 +1152,7 @@ app.controller("JsonDataController", [ $timeout, $location, authService, - service + fileServices ) { $scope.request = { pageSize: "10", @@ -1462,35 +1167,39 @@ app.controller("JsonDataController", [ }; $scope.activedFile = null; - $scope.editorVisible = false; - $scope.data = null; $scope.relatedFiles = []; $rootScope.isBusy = false; - + $scope.data = { + pageIndex: 0, + pageSize: 1, + totalItems: 0, + }; $scope.errors = []; + $scope.range = function (max) { + var input = []; + for (var i = 1; i <= max; i += 1) input.push(i); + return input; + }; $scope.loadPage = async function (folder) { if (folder) { - $scope.request.key += $scope.request.key !== "" ? "/" : ""; - $scope.request.key += folder; + $scope.request.folder += $scope.request.folder !== "" ? "/" : ""; + $scope.request.folder += folder; } $location.url( - "/admin/json-data/list?folder=" + encodeURIComponent($scope.request.key) + "/admin/file/list?folder=" + encodeURIComponent($scope.request.folder) ); }; - $scope.init = async function () { + $scope.loadFile = async function () { $rootScope.isBusy = true; - $scope.filename = $routeParams.filename; - $scope.folder = $routeParams.folder; - $scope.listUrl = "/admin/json-data/list?folder=" + $routeParams.folder; + $scope.listUrl = "/admin/file/list?folder/" + $routeParams.folder; $rootScope.isBusy = true; - var response = await service.getFile( + var response = await fileServices.getFile( $routeParams.folder, $routeParams.filename ); if (response.success) { $scope.activedFile = response.data; - $scope.data = $.parseJSON(response.data.content); $rootScope.isBusy = false; $scope.$apply(); } else { @@ -1501,14 +1210,26 @@ app.controller("JsonDataController", [ }; $scope.loadFiles = async function (folder) { if (folder) { - $scope.request.key += $scope.request.key !== "" ? "/" : ""; - $scope.request.key += folder; + $scope.request.folder += + $scope.request.folder !== "" + ? "MixContent/StaticFiles" + : "MixContent/StaticFiles"; + $scope.request.folder += folder; } else { - $scope.request.key = $routeParams.folder ? $routeParams.folder : "data"; + $scope.request.folder = $routeParams.folder + ? $routeParams.folder + : "MixContent/StaticFiles"; + } + if ($routeParams.folder) { + $scope.backUrl = + "/admin/file/list?folder=" + + $routeParams.folder.substring( + 0, + $routeParams.folder.lastIndexOf("/") + ); } - $rootScope.isBusy = true; - var resp = await service.getFiles($scope.request); + var resp = await fileServices.getFiles($scope.request); if (resp && resp.success) { $scope.data = resp.data; $.each($scope.data.items, function (i, file) { @@ -1532,7 +1253,7 @@ app.controller("JsonDataController", [ $scope.removeFile = async function (id) { if (confirm("Are you sure!")) { $rootScope.isBusy = true; - var resp = await service.removeFile(id); + var resp = await fileServices.removeFile(id); if (resp && resp.success) { $scope.loadFiles(); } else { @@ -1544,20 +1265,10 @@ app.controller("JsonDataController", [ } } }; - $scope.selectPane = function (pane) { - $scope.editorVisible = pane.header == "Content"; - }; - $scope.save = async function (data) { - $scope.activedFile.contennt = JSON.stringify(data); - $scope.saveFile($scope.activedFile); - }; - $scope.updateData = async function (data) { - $scope.data = data; - }; + $scope.saveFile = async function (file) { $rootScope.isBusy = true; - file.content = JSON.stringify($scope.data); - var resp = await service.saveFile(file); + var resp = await fileServices.saveFile(file); if (resp && resp.success) { $scope.activedFile = resp.data; $rootScope.showMessage("Update successfully!", "success"); @@ -1571,23 +1282,25 @@ app.controller("JsonDataController", [ $scope.$apply(); } }; + $scope.updateTemplateContent = function (content) { + $scope.activedFile.content = content; + }; }, ]); "use strict"; -app.factory("JsonDataService", [ +app.factory("FileServices", [ "$http", "$rootScope", "ApiService", "CommonService", - function ($http, $rootScope, apiService, commonService) { - var filesServiceFactory = {}; - - var settings = $rootScope.globalSettings; - + "BaseRestService", + function ($http, $rootScope, apiService, commonService, baseService) { + var filesServiceFactory = angular.copy(baseService); + filesServiceFactory.initService("/rest", "mix-storage/file-system", true); var _getFile = async function (folder, filename) { - var apiUrl = "/file/"; - var url = apiUrl + "details?folder=" + folder + "&filename=" + filename; + var url = + this.prefixUrl + "/details?folder=" + folder + "&filename=" + filename; var req = { method: "GET", url: url, @@ -1596,287 +1309,358 @@ app.factory("JsonDataService", [ }; var _initFile = async function (type) { - var apiUrl = "/file/"; var req = { method: "GET", - url: apiUrl + "init/" + type, + url: this.prefixUrl + "/init/" + type, }; return await apiService.sendRequest(req); }; var _getFiles = async function (request) { - var apiUrl = "/file/"; + var url = this.prefixUrl; + var data = filesServiceFactory.parseQuery(request); + if (data) { + url += "?"; + url = url.concat(data); + } var req = { - method: "POST", - url: apiUrl + "list", + method: "GET", + url: url, data: JSON.stringify(request), }; - return await apiService.sendRequest(req); }; - var _removeFile = async function (id) { - var apiUrl = "/file/"; + var _removeFile = async function (fullPath) { var req = { - method: "GET", - url: apiUrl + "delete/" + id, + method: "DELETE", + url: this.prefixUrl + "/delete/?fullPath=" + fullPath, }; return await apiService.sendRequest(req); }; var _saveFile = async function (file) { - var apiUrl = "/file/"; var req = { method: "POST", - url: apiUrl + "save", + url: this.prefixUrl + "/save", data: JSON.stringify(file), }; return await apiService.sendRequest(req); }; + var _uploadFile = async function (file, folder) { + var apiUrl = this.prefixUrl + "/upload-file"; + var fd = new FormData(); + fd.append("folder", folder); + fd.append("file", file); + return await filesServiceFactory.ajaxSubmitForm(fd, apiUrl); + }; + + var _extractFile = async function (file, folder) { + var apiUrl = this.prefixUrl + "/extract-file"; + var fd = new FormData(); + fd.append("folder", folder); + fd.append("file", file); + return await filesServiceFactory.ajaxSubmitForm(fd, apiUrl); + }; filesServiceFactory.getFile = _getFile; filesServiceFactory.initFile = _initFile; filesServiceFactory.getFiles = _getFiles; filesServiceFactory.removeFile = _removeFile; filesServiceFactory.saveFile = _saveFile; + filesServiceFactory.uploadFile = _uploadFile; + filesServiceFactory.extractFile = _extractFile; return filesServiceFactory; }, ]); "use strict"; -app.controller("LocalizeController", [ +app.controller("ImportFileController", [ "$scope", "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "LocalizeService", - "ApiService", - "CommonService", + "ImportFileServices", + "TranslatorService", + "AppSettingsService", function ( $scope, $rootScope, - ngAppSettings, - $routeParams, - $location, service, - commonService + translatorService, + AppSettingsService ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - service - ); - - $scope.getSingleSuccessCallback = function () { - $scope.cates = ngAppSettings.enums.configuration_cates; - $scope.appSettings = $rootScope.globalSettings; - $scope.request.category = $routeParams.category || ""; - if (!$scope.viewmodel.id) { - $scope.viewmodel.dataType = "Text"; - } - if (!$scope.viewmodel.category) { - $scope.viewmodel.category = "Site"; - } - }; - $scope.saveSuccessCallback = function () { - apiService.getAllSettings().then(function () { - // $location.url($scope.referrerUrl); + $scope.saveImportFile = async function () { + $rootScope.isBusy = true; + var form = document.getElementById("frm-import"); + var frm = new FormData(); + frm.append("assets", form["assets"].files[0]); + var response = await service.saveImportFile(frm); + if (response.success) { + $scope.viewmodel = response.data; $rootScope.isBusy = false; $scope.$apply(); - }); - }; - $scope.removeCallback = function () { - apiService.getAllSettings().then(function () { - $location.url($scope.referrerUrl); - }); - }; - - $scope.generateName = function () { - $scope.viewmodel.keyword = $rootScope.generateKeyword( - $scope.viewmodel.keyword, - "_", - true - ); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } }; }, ]); "use strict"; -app.factory("LocalizeService", [ - "BaseRestService", - "ApiService", - "CommonService", - function (baseService, apiService, commonService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("language"); - - var _uploadLanguage = async function (languageFile) { - //var container = $(this).parents('.model-language').first().find('.custom-file').first(); - if (languageFile.file !== undefined && languageFile.file !== null) { - // Create FormData object - var files = new FormData(); - - // Looping over all files and add it to FormData object - files.append(languageFile.file.name, languageFile.file); - - // Adding one more key to FormData object - files.append("fileFolder", languageFile.folder); - files.append("title", languageFile.title); - files.append("description", languageFile.description); +app.factory("ImportFileServices", [ + "$rootScope", + "BaseService", + function ($rootScope, baseService) { + //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; - var req = { - url: this.prefixUrl + "/upload", - type: "POST", - headers: {}, - contentType: false, // Not to set any content header - processData: false, // Not to process data - data: files, - }; + var serviceFactory = {}; - return await apiService.sendRequest(req); - } + var settings = $rootScope.globalSettings; + var serviceFactory = Object.create(baseService); + serviceFactory.init("portal", true); + var _saveImportFile = async function (frm) { + var apiUrl = this.prefixUrl + "/" + settings.lang + "/import"; + return await this.ajaxSubmitForm(frm, apiUrl); }; - serviceFactory.uploadLanguage = _uploadLanguage; + + serviceFactory.saveImportFile = _saveImportFile; return serviceFactory; }, ]); "use strict"; -app.controller("loginController", [ - "$rootScope", +app.controller("JsonDataController", [ "$scope", + "$rootScope", "ngAppSettings", + "$routeParams", + "$timeout", "$location", "AuthService", - "ngAppSettings", + "JsonDataService", function ( - $rootScope, $scope, + $rootScope, ngAppSettings, + $routeParams, + $timeout, $location, authService, - ngAuthSettings + service ) { - if ( - authService.authentication && - authService.authentication.isAuth && - authService.authentication.isAdmin - ) { - authService.referredUrl = $location.path(); - $location.path("/admin"); - } + $scope.request = { + pageSize: "10", + pageIndex: 0, + status: "Published", + orderBy: "CreatedDateTime", + direction: "Desc", + fromDate: null, + toDate: null, + keyword: "", + key: "", + }; - $scope.pageClass = "page-login"; + $scope.activedFile = null; + $scope.editorVisible = false; + $scope.data = null; + $scope.relatedFiles = []; + $rootScope.isBusy = false; - $scope.loginData = { - username: "", - password: "", - rememberme: true, - }; + $scope.errors = []; - $scope.message = ""; - $scope.$on("$viewContentLoaded", function () { - $rootScope.isBusy = false; - }); - $scope.login = async function () { - if (authService.referredUrl === "/init/login") { - authService.referredUrl = "/admin"; + $scope.loadPage = async function (folder) { + if (folder) { + $scope.request.key += $scope.request.key !== "" ? "/" : ""; + $scope.request.key += folder; } + $location.url( + "/admin/json-data/list?folder=" + encodeURIComponent($scope.request.key) + ); + }; + $scope.init = async function () { $rootScope.isBusy = true; - var result = await authService.login($scope.loginData); - if (result.success) { - if ($routeParams.ReturnUrl) { - window.top.location = $routeParams.ReturnUrl; - } else if ( - document.referrer && - document.referrer.indexOf("init") === -1 - ) { - window.top.location = document.referrer; - } else { - window.top.location = "/"; + $scope.filename = $routeParams.filename; + $scope.folder = $routeParams.folder; + $scope.listUrl = "/admin/json-data/list?folder=" + $routeParams.folder; + $rootScope.isBusy = true; + var response = await service.getFile( + $routeParams.folder, + $routeParams.filename + ); + if (response.success) { + $scope.activedFile = response.data; + $scope.data = $.parseJSON(response.data.content); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.loadFiles = async function (folder) { + if (folder) { + $scope.request.key += $scope.request.key !== "" ? "/" : ""; + $scope.request.key += folder; + } else { + $scope.request.key = $routeParams.folder ? $routeParams.folder : "data"; + } + + $rootScope.isBusy = true; + var resp = await service.getFiles($scope.request); + if (resp && resp.success) { + $scope.data = resp.data; + $.each($scope.data.items, function (i, file) { + $.each($scope.activedFiles, function (i, e) { + if (e.fileId === file.id) { + file.isHidden = true; + } + }); + }); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); } + $rootScope.isBusy = false; + $scope.$apply(); } - $rootScope.isBusy = false; - $scope.$apply(); }; - $scope.authExternalProvider = function (provider) { - var redirectUri = - location.protocol + "//" + location.host + "/authcomplete.html"; + $scope.removeFile = async function (id) { + if (confirm("Are you sure!")) { + $rootScope.isBusy = true; + var resp = await service.removeFile(id); + if (resp && resp.success) { + $scope.loadFiles(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + } + }; + $scope.selectPane = function (pane) { + $scope.editorVisible = pane.header == "Content"; + }; + $scope.save = async function (data) { + $scope.activedFile.contennt = JSON.stringify(data); + $scope.saveFile($scope.activedFile); + }; + $scope.updateData = async function (data) { + $scope.data = data; + }; + $scope.saveFile = async function (file) { + $rootScope.isBusy = true; + file.content = JSON.stringify($scope.data); + var resp = await service.saveFile(file); + if (resp && resp.success) { + $scope.activedFile = resp.data; + $rootScope.showMessage("Update successfully!", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, +]); - var externalProviderUrl = - ngAuthSettings.apiServiceBaseUri + - "api/Account/ExternalLogin?provider=" + - provider + - "&response_type=token&client_id=" + - ngAuthSettings.clientId + - "&redirect_uri=" + - redirectUri; - window.$windowScope = $scope; +"use strict"; +app.factory("JsonDataService", [ + "$http", + "$rootScope", + "ApiService", + "CommonService", + function ($http, $rootScope, apiService, commonService) { + var filesServiceFactory = {}; - var oauthWindow = window.open( - externalProviderUrl, - "Authenticate Account", - "location=0,status=0,width=600,height=750" - ); + var settings = $rootScope.globalSettings; + + var _getFile = async function (folder, filename) { + var apiUrl = "/file/"; + var url = apiUrl + "details?folder=" + folder + "&filename=" + filename; + var req = { + method: "GET", + url: url, + }; + return await apiService.sendRequest(req); }; - $scope.authCompletedCB = function (fragment) { - $scope.$apply(function () { - if (fragment.haslocalaccount === "False") { - authService.logOut(); + var _initFile = async function (type) { + var apiUrl = "/file/"; + var req = { + method: "GET", + url: apiUrl + "init/" + type, + }; + return await apiService.sendRequest(req); + }; - authService.externalAuthData = { - provider: fragment.provider, - username: fragment.external_user_name, - externalAccessToken: fragment.external_access_token, - }; + var _getFiles = async function (request) { + var apiUrl = "/file/"; + var req = { + method: "POST", + url: apiUrl + "list", + data: JSON.stringify(request), + }; - $location.path("/associate"); - } else { - //Obtain access token and redirect to orders - var externalData = { - provider: fragment.provider, - externalAccessToken: fragment.external_access_token, - }; - authService.obtainAccessToken(externalData).then( - function (response) { - $location.path("/orders"); - }, - function (err) { - $scope.message = err.error_description; - } - ); - } - }); + return await apiService.sendRequest(req); + }; + + var _removeFile = async function (id) { + var apiUrl = "/file/"; + var req = { + method: "GET", + url: apiUrl + "delete/" + id, + }; + return await apiService.sendRequest(req); + }; + + var _saveFile = async function (file) { + var apiUrl = "/file/"; + var req = { + method: "POST", + url: apiUrl + "save", + data: JSON.stringify(file), + }; + return await apiService.sendRequest(req); }; + + filesServiceFactory.getFile = _getFile; + filesServiceFactory.initFile = _initFile; + filesServiceFactory.getFiles = _getFiles; + filesServiceFactory.removeFile = _removeFile; + filesServiceFactory.saveFile = _saveFile; + return filesServiceFactory; }, ]); "use strict"; -app.controller("MixDatabaseController", [ +app.controller("LocalizeController", [ "$scope", "$rootScope", - "$location", "ngAppSettings", "$routeParams", - "RestMixDatabaseDataPortalService", - "RestMixDatabaseColumnPortalService", - "RestMixDatabasePortalService", + "$location", + "LocalizeService", + "ApiService", + "CommonService", function ( $scope, $rootScope, - $location, ngAppSettings, $routeParams, - databaseDataService, - databaseColumnService, - databaseService + $location, + service, + commonService ) { BaseRestCtrl.call( this, @@ -1885,37 +1669,254 @@ app.controller("MixDatabaseController", [ $location, $routeParams, ngAppSettings, - databaseService + service ); - $scope.defaultAttr = null; - $scope.actions = ["Delete"]; - // $scope.request.selects = 'id,title,name,createdDateTime'; - $scope.orders = [ - { title: "Id", value: "Id" }, - { title: "Name", value: "Name" }, - { title: "Created Date", value: "CreatedDateTime" }, - ]; - $scope.request.orderBy = "CreatedDateTime"; - $scope.request.columns = "id,displayName,systemName,type,createdDatetime"; - $scope.saveDatabase = function () { - $scope.save($scope.viewmodel); + + $scope.getSingleSuccessCallback = function () { + $scope.cates = ngAppSettings.enums.configuration_cates; + $scope.appSettings = $rootScope.globalSettings; + $scope.request.category = $routeParams.category || ""; + if (!$scope.viewmodel.id) { + $scope.viewmodel.dataType = "Text"; + } + if (!$scope.viewmodel.category) { + $scope.viewmodel.category = "Site"; + } }; - $scope.getSingleSuccessCallback = async function () { - if (!$scope.defaultAttr) { - var getDefaultAttr = await databaseColumnService.getDefault(); - if (getDefaultAttr.success) { - $scope.defaultAttr = getDefaultAttr.data; - $scope.defaultAttr.options = []; - } + $scope.saveSuccessCallback = function () { + apiService.getAllSettings().then(function () { + // $location.url($scope.referrerUrl); + $rootScope.isBusy = false; $scope.$apply(); - } + }); }; - $scope.migrate = async function () { - if ($scope.viewmodel.id) { - $rootScope.isBusy = true; - var result = await databaseService.migrate($scope.viewmodel); - if (result.success) { - $rootScope.showMessage( + $scope.removeCallback = function () { + apiService.getAllSettings().then(function () { + $location.url($scope.referrerUrl); + }); + }; + + $scope.generateName = function () { + $scope.viewmodel.keyword = $rootScope.generateKeyword( + $scope.viewmodel.keyword, + "_", + true + ); + }; + }, +]); + +"use strict"; +app.factory("LocalizeService", [ + "BaseRestService", + "ApiService", + "CommonService", + function (baseService, apiService, commonService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("language"); + + var _uploadLanguage = async function (languageFile) { + //var container = $(this).parents('.model-language').first().find('.custom-file').first(); + if (languageFile.file !== undefined && languageFile.file !== null) { + // Create FormData object + var files = new FormData(); + + // Looping over all files and add it to FormData object + files.append(languageFile.file.name, languageFile.file); + + // Adding one more key to FormData object + files.append("fileFolder", languageFile.folder); + files.append("title", languageFile.title); + files.append("description", languageFile.description); + + var req = { + url: this.prefixUrl + "/upload", + type: "POST", + headers: {}, + contentType: false, // Not to set any content header + processData: false, // Not to process data + data: files, + }; + + return await apiService.sendRequest(req); + } + }; + serviceFactory.uploadLanguage = _uploadLanguage; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("loginController", [ + "$rootScope", + "$scope", + "ngAppSettings", + "$location", + "AuthService", + "ngAppSettings", + function ( + $rootScope, + $scope, + ngAppSettings, + $location, + authService, + ngAuthSettings + ) { + if ( + authService.authentication && + authService.authentication.isAuth && + authService.authentication.isAdmin + ) { + authService.referredUrl = $location.path(); + $location.path("/admin"); + } + + $scope.pageClass = "page-login"; + + $scope.loginData = { + username: "", + password: "", + rememberme: true, + }; + + $scope.message = ""; + $scope.$on("$viewContentLoaded", function () { + $rootScope.isBusy = false; + }); + $scope.login = async function () { + if (authService.referredUrl === "/init/login") { + authService.referredUrl = "/admin"; + } + $rootScope.isBusy = true; + var result = await authService.login($scope.loginData); + if (result.success) { + if ($routeParams.ReturnUrl) { + window.top.location = $routeParams.ReturnUrl; + } else if ( + document.referrer && + document.referrer.indexOf("init") === -1 + ) { + window.top.location = document.referrer; + } else { + window.top.location = "/"; + } + } + $rootScope.isBusy = false; + $scope.$apply(); + }; + + $scope.authExternalProvider = function (provider) { + var redirectUri = + location.protocol + "//" + location.host + "/authcomplete.html"; + + var externalProviderUrl = + ngAuthSettings.apiServiceBaseUri + + "api/Account/ExternalLogin?provider=" + + provider + + "&response_type=token&client_id=" + + ngAuthSettings.clientId + + "&redirect_uri=" + + redirectUri; + window.$windowScope = $scope; + + var oauthWindow = window.open( + externalProviderUrl, + "Authenticate Account", + "location=0,status=0,width=600,height=750" + ); + }; + + $scope.authCompletedCB = function (fragment) { + $scope.$apply(function () { + if (fragment.haslocalaccount === "False") { + authService.logOut(); + + authService.externalAuthData = { + provider: fragment.provider, + username: fragment.external_user_name, + externalAccessToken: fragment.external_access_token, + }; + + $location.path("/associate"); + } else { + //Obtain access token and redirect to orders + var externalData = { + provider: fragment.provider, + externalAccessToken: fragment.external_access_token, + }; + authService.obtainAccessToken(externalData).then( + function (response) { + $location.path("/orders"); + }, + function (err) { + $scope.message = err.error_description; + } + ); + } + }); + }; + }, +]); + +"use strict"; +app.controller("MixDatabaseController", [ + "$scope", + "$rootScope", + "$location", + "ngAppSettings", + "$routeParams", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", + "RestMixDatabasePortalService", + function ( + $scope, + $rootScope, + $location, + ngAppSettings, + $routeParams, + databaseDataService, + databaseColumnService, + databaseService + ) { + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + databaseService + ); + $scope.defaultAttr = null; + $scope.actions = ["Delete"]; + $scope.viewmodelType = "mix-database"; + // $scope.request.selects = 'id,title,name,createdDateTime'; + $scope.orders = [ + { title: "Id", value: "Id" }, + { title: "Name", value: "Name" }, + { title: "Created Date", value: "CreatedDateTime" }, + ]; + $scope.request.orderBy = "CreatedDateTime"; + $scope.request.columns = "id,displayName,systemName,type,createdDatetime"; + $scope.saveDatabase = function () { + $scope.save($scope.viewmodel); + }; + $scope.getSingleSuccessCallback = async function () { + if (!$scope.defaultAttr) { + var getDefaultAttr = await databaseColumnService.getDefault(); + if (getDefaultAttr.success) { + $scope.defaultAttr = getDefaultAttr.data; + $scope.defaultAttr.options = []; + } + $scope.$apply(); + } + }; + $scope.migrate = async function () { + if ($scope.viewmodel.id) { + $rootScope.isBusy = true; + var result = await databaseService.migrate($scope.viewmodel); + if (result.success) { + $rootScope.showMessage( "Please restart pool to apply new db schema", "warning" ); @@ -3242,43 +3243,193 @@ app.factory("RestOrderDetailService", [ ]); "use strict"; -app.controller("PageController", [ +app.controller("PageGalleryController", [ "$scope", "$rootScope", "ngAppSettings", - "$location", "$routeParams", - "PageRestService", - "PagePostRestService", - "UrlAliasService", - "RestMixDatabasePortalService", - "RestMixDatabaseDataPortalService", - "RestMixDatabaseColumnPortalService", - "MixDbService", + "$location", + "PageGalleryService", + "PostRestService", + "ApiService", + "CommonService", function ( $scope, $rootScope, ngAppSettings, - $location, $routeParams, + $location, service, - pagePostRestService, - urlAliasService, - databaseService, - dataService, - columnService, - mixDbService + postService, + apiService, + commonService ) { - BaseRestCtrl.call( + BaseCtrl.call( this, $scope, $rootScope, - $location, $routeParams, ngAppSettings, service ); - $scope.request.culture = $rootScope.globalSettings.defaultCulture; + $scope.cates = ["Site", "System"]; + $scope.others = []; + $scope.mixConfigurations = $rootScope.globalSettings; + $scope.pageId = $routeParams.id; + $scope.canDrag = + $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; + $scope.getList = async function () { + $rootScope.isBusy = true; + var id = $routeParams.id; + $scope.request.query = "&page_id=" + id; + var response = await service.getList($scope.request); + $scope.canDrag = + $scope.request.orderBy !== "Priority" || + $scope.request.direction !== "0"; + if (response.success) { + $scope.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.remove = function (pageId, postId) { + $rootScope.showConfirm( + $scope, + "removeConfirmed", + [pageId, postId], + null, + "Remove", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + $scope.removeConfirmed = async function (pageId, postId) { + $rootScope.isBusy = true; + var result = await service.delete(pageId, postId); + if (result.success) { + if ($scope.removeCallback) { + $rootScope.executeFunctionByName( + "removeCallback", + $scope.removeCallbackArgs, + $scope + ); + } + $scope.getList(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.saveOthers = async function () { + var response = await service.saveList($scope.others); + if (response.success) { + $scope.getList(); + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.updateInfos = async function (index) { + $scope.data.items.splice(index, 1); + $rootScope.isBusy = true; + var startIndex = $scope.data.items[0].priority - 1; + for (var i = 0; i < $scope.data.items.length; i++) { + $scope.data.items[i].priority = startIndex + i + 1; + } + var resp = await service.updateInfos($scope.data.items); + if (resp && resp.success) { + $scope.activedPage = resp.data; + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, +]); + +"use strict"; +app.factory("PageGalleryService", [ + "$rootScope", + "ApiService", + "CommonService", + "BaseService", + function ($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("page-post"); + var _delete = async function (pageId, postId) { + var url = this.prefixUrl + "/delete/" + pageId + "/" + postId; + var req = { + method: "GET", + url: url, + }; + return await apiService.sendRequest(req); + }; + var _updateInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-infos", + data: JSON.stringify(pages), + }; + return await apiService.sendRequest(req); + }; + serviceFactory.delete = _delete; + serviceFactory.updateInfos = _updateInfos; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("PageController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$location", + "$routeParams", + "PageRestService", + "PagePostRestService", + "UrlAliasService", + "RestMixDatabasePortalService", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", + "MixDbService", + function ( + $scope, + $rootScope, + ngAppSettings, + $location, + $routeParams, + service, + pagePostRestService, + urlAliasService, + databaseService, + dataService, + columnService, + mixDbService + ) { + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + service + ); + $scope.request.culture = $rootScope.globalSettings.defaultCulture; var pageModuleService = $rootScope.getRestService("mix-page-module"); $scope.viewmodelType = "page"; $scope.request.query = "level=0"; @@ -3598,13 +3749,13 @@ app.factory("PageRestService", [ ]); "use strict"; -app.controller("PageGalleryController", [ +app.controller("PagePostController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "PageGalleryService", + "PagePostRestService", "PostRestService", "ApiService", "CommonService", @@ -3616,7 +3767,6 @@ app.controller("PageGalleryController", [ $location, service, postService, - apiService, commonService ) { BaseCtrl.call( @@ -3627,20 +3777,39 @@ app.controller("PageGalleryController", [ ngAppSettings, service ); + $scope.request.culture = $rootScope.globalSettings.defaultCulture; $scope.cates = ["Site", "System"]; $scope.others = []; $scope.mixConfigurations = $rootScope.globalSettings; - $scope.pageId = $routeParams.id; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.getList = async function () { + $scope.init = function () { + $scope.pageId = $routeParams.id; + $scope.type = $routeParams.type || ""; + $scope.template = $routeParams.template || ""; + $scope.pageIds = $routeParams.page_ids || $routeParams.id || ""; + $scope.moduleIds = $routeParams.module_ids || ""; + $scope.canDrag = + $scope.request.orderBy === "Priority" && + $scope.request.direction === "Asc"; + $scope.createUrl = + $routeParams.post_type === "gallery" + ? "/admin/post/create-gallery" + : `/admin/post/create?page_ids=${$scope.pageIds}&moduleIds=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; + $scope.updateUrl = + $routeParams.post_type === "gallery" + ? "/admin/post/gallery-details" + : "/admin/post/details"; + }; + $scope.getList = async function (pageIndex) { + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } $rootScope.isBusy = true; var id = $routeParams.id; $scope.request.query = "&page_id=" + id; var response = await service.getList($scope.request); $scope.canDrag = - $scope.request.orderBy !== "Priority" || - $scope.request.direction !== "0"; + $scope.request.orderBy === "Priority" && + $scope.request.direction === "Asc"; if (response.success) { $scope.data = response.data; $rootScope.isBusy = false; @@ -3651,6 +3820,10 @@ app.controller("PageGalleryController", [ $scope.$apply(); } }; + $scope.preview = function (item) { + item.editUrl = "/admin/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); + }; $scope.remove = function (pageId, postId) { $rootScope.showConfirm( $scope, @@ -3661,10 +3834,13 @@ app.controller("PageGalleryController", [ "Deleted data will not able to recover, are you sure you want to delete this item?" ); }; + $scope.back = function () { + window.history.back(); + }; - $scope.removeConfirmed = async function (pageId, postId) { + $scope.removeConfirmed = async function (id) { $rootScope.isBusy = true; - var result = await service.delete(pageId, postId); + var result = await service.delete(id); if (result.success) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -3675,7 +3851,7 @@ app.controller("PageGalleryController", [ } $scope.getList(); } else { - $rootScope.showMessage("failed"); + $rootScope.showErrors(result.errors); $rootScope.isBusy = false; $scope.$apply(); } @@ -3717,21 +3893,21 @@ app.controller("PageGalleryController", [ ]); "use strict"; -app.factory("PageGalleryService", [ +app.factory("PagePostRestService", [ "$rootScope", "ApiService", "CommonService", - "BaseService", + "BaseRestService", function ($rootScope, apiService, commonService, baseService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("page-post"); - var _delete = async function (pageId, postId) { - var url = this.prefixUrl + "/delete/" + pageId + "/" + postId; + serviceFactory.init("mix-page-post"); + var _delete = async function (id) { + var url = this.prefixUrl + "/delete/" + id; var req = { method: "GET", url: url, }; - return await apiService.sendRequest(req); + return await apiService.getApiResult(req); }; var _updateInfos = async function (pages) { var req = { @@ -3739,7 +3915,7 @@ app.factory("PageGalleryService", [ url: this.prefixUrl + "/update-infos", data: JSON.stringify(pages), }; - return await apiService.sendRequest(req); + return await apiService.getApiResult(req); }; serviceFactory.delete = _delete; serviceFactory.updateInfos = _updateInfos; @@ -3748,207 +3924,32 @@ app.factory("PageGalleryService", [ ]); "use strict"; -app.controller("PagePostController", [ +app.controller("PermissionController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "PagePostRestService", - "PostRestService", "ApiService", "CommonService", + "PermissionService", + "RestPortalPageNavigationService", function ( $scope, $rootScope, ngAppSettings, $routeParams, $location, + apiService, + commonService, service, - postService, - commonService + navService ) { - BaseCtrl.call( + BaseRestCtrl.call( this, $scope, $rootScope, - $routeParams, - ngAppSettings, - service - ); - $scope.request.culture = $rootScope.globalSettings.defaultCulture; - $scope.cates = ["Site", "System"]; - $scope.others = []; - $scope.mixConfigurations = $rootScope.globalSettings; - $scope.init = function () { - $scope.pageId = $routeParams.id; - $scope.type = $routeParams.type || ""; - $scope.template = $routeParams.template || ""; - $scope.pageIds = $routeParams.page_ids || $routeParams.id || ""; - $scope.moduleIds = $routeParams.module_ids || ""; - $scope.canDrag = - $scope.request.orderBy === "Priority" && - $scope.request.direction === "Asc"; - $scope.createUrl = - $routeParams.post_type === "gallery" - ? "/admin/post/create-gallery" - : `/admin/post/create?page_ids=${$scope.pageIds}&moduleIds=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; - $scope.updateUrl = - $routeParams.post_type === "gallery" - ? "/admin/post/gallery-details" - : "/admin/post/details"; - }; - $scope.getList = async function (pageIndex) { - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } - $rootScope.isBusy = true; - var id = $routeParams.id; - $scope.request.query = "&page_id=" + id; - var response = await service.getList($scope.request); - $scope.canDrag = - $scope.request.orderBy === "Priority" && - $scope.request.direction === "Asc"; - if (response.success) { - $scope.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.preview = function (item) { - item.editUrl = "/admin/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); - }; - $scope.remove = function (pageId, postId) { - $rootScope.showConfirm( - $scope, - "removeConfirmed", - [pageId, postId], - null, - "Remove", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - $scope.back = function () { - window.history.back(); - }; - - $scope.removeConfirmed = async function (id) { - $rootScope.isBusy = true; - var result = await service.delete(id); - if (result.success) { - if ($scope.removeCallback) { - $rootScope.executeFunctionByName( - "removeCallback", - $scope.removeCallbackArgs, - $scope - ); - } - $scope.getList(); - } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - - $scope.saveOthers = async function () { - var response = await service.saveList($scope.others); - if (response.success) { - $scope.getList(); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.updateInfos = async function (index) { - $scope.data.items.splice(index, 1); - $rootScope.isBusy = true; - var startIndex = $scope.data.items[0].priority - 1; - for (var i = 0; i < $scope.data.items.length; i++) { - $scope.data.items[i].priority = startIndex + i + 1; - } - var resp = await service.updateInfos($scope.data.items); - if (resp && resp.success) { - $scope.activedPage = resp.data; - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - }, -]); - -"use strict"; -app.factory("PagePostRestService", [ - "$rootScope", - "ApiService", - "CommonService", - "BaseRestService", - function ($rootScope, apiService, commonService, baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("mix-page-post"); - var _delete = async function (id) { - var url = this.prefixUrl + "/delete/" + id; - var req = { - method: "GET", - url: url, - }; - return await apiService.getApiResult(req); - }; - var _updateInfos = async function (pages) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), - }; - return await apiService.getApiResult(req); - }; - serviceFactory.delete = _delete; - serviceFactory.updateInfos = _updateInfos; - return serviceFactory; - }, -]); - -"use strict"; -app.controller("PermissionController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "ApiService", - "CommonService", - "PermissionService", - "RestPortalPageNavigationService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - $location, - apiService, - commonService, - service, - navService - ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, + $location, $routeParams, ngAppSettings, service @@ -4070,34 +4071,24 @@ app.factory("RestPortalPageNavigationService", [ ]); "use strict"; -app.controller("PostController", [ +app.controller("RoleController", [ "$scope", "$rootScope", "$location", - "$filter", - "ngAppSettings", "$routeParams", - "PostRestService", - "UrlAliasService", + "ngAppSettings", "RestMixDatabaseDataPortalService", "RestMixDatabaseColumnPortalService", - "RestRelatedAttributeDataPortalService", - "RestMixDatabasePortalService", - "MixDbService", + "RoleService", function ( $scope, $rootScope, $location, - $filter, - ngAppSettings, $routeParams, - service, - urlAliasService, + ngAppSettings, dataService, columnService, - navService, - databaseService, - mixDbService + service ) { BaseRestCtrl.call( this, @@ -4108,841 +4099,851 @@ app.controller("PostController", [ ngAppSettings, service ); - if (!$scope.referrerUrl) { - $scope.referrerUrl = "/admin/post/list"; - } - $scope.request.searchColumns = "title"; - $scope.request.culture = $rootScope.globalSettings.defaultCulture; - $scope.request.queries = []; - $scope.defaultQuery = { - fieldName: "", - compareOperator: "Equal", - value: "", + $scope.role = { name: "" }; + $scope.initPermissions = async function () { + let backUrl = "/admin/role/list"; + $scope.createUrl = `/admin/mix-database-data/create?mixDatabaseName=sysPermission&dataContentId=default&guidParentId=${$scope.viewmodel.id}&parentType=Role&backUrl=${backUrl}`; + $scope.updateUrl = "/admin/mix-database-data/details"; }; - $scope.viewmodelType = "post"; - $scope.additionalData = {}; - $scope.createUrl = "/admin/post/create?"; - $scope.postTypeRequest = angular.copy(ngAppSettings.request); - ($scope.postTypeRequest.searchColumns = "Type"), - ($scope.postTypeRequest.searchMethod = "Equal"), - ($scope.postTypeRequest.keyword = "AdditionalData"); - $scope.initList = async function () { - if ($routeParams.template) { - $scope.createUrl = `${$scope.createUrl}&template=${$routeParams.template}`; - } - if ($routeParams.category) { - $scope.request.category = $routeParams.category; - } - if ($routeParams.type) { - $scope.createUrl = `${$scope.createUrl}&type=${$routeParams.type}`; - $scope.request.additionalDatabase = $routeParams.type; - $scope.request.mixDatabaseName = $routeParams.type; - } - if ($routeParams.layout) { - $scope.createUrl = `${$scope.createUrl}&layout=${$routeParams.layout}`; - } - if ($routeParams.page_ids) { - $scope.createUrl = `${$scope.createUrl}&page_ids=${$routeParams.page_ids}`; + $scope.createRole = async function () { + $rootScope.isBusy = true; + var result = await service.createRole($scope.role.name); + if (result.success) { + $scope.role.name = ""; + $scope.getList(); + } else { + $rootScope.showErrors(result.errors); + $rootScope.isBusy = false; + $scope.$apply(); } - $scope.pageName = "postList"; - await $scope.loadAdditionalDatabases(); - $scope.filter(); }; + }, +]); - $scope.parseQueryField = function (fieldName, value, operator = "Equal") { - return { - fieldName: fieldName, - value: value, - compareOperator: operator, +"use strict"; +app.factory("RoleService", [ + "BaseRestService", + "ApiService", + "CommonService", + function (baseService, apiService, commonService) { + var serviceFactory = Object.create(baseService); + serviceFactory.initService("/rest/mix-account", "role", true); + + var _getPermissions = async function () { + var req = { + method: "GET", + url: this.prefixUrl + "/permissions", }; + return await apiService.sendRequest(req); }; - $scope.filter = async function (pageIndex) { - $rootScope.isBusy = true; - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } - if ($scope.request.fromDate !== null) { - var d = new Date($scope.request.fromDate); - $scope.request.fromDate = d.toISOString(); - } - if ($scope.request.toDate !== null) { - var dt = new Date($scope.request.toDate); - $scope.request.toDate = dt.toISOString(); + + var _updatePermission = async function (permission) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-permission", + data: JSON.stringify(permission), + }; + return await apiService.sendRequest(req); + }; + var _createRole = function (name) { + var req = { + method: "POST", + url: this.prefixUrl + "/create", + data: JSON.stringify(name), + }; + + return apiService.sendRequest(req); + }; + serviceFactory.createRole = _createRole; + serviceFactory.getPermissions = _getPermissions; + serviceFactory.updatePermission = _updatePermission; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("SchedulerController", [ + "$scope", + "$rootScope", + "$routeParams", + "$location", + "SchedulerService", + function ($scope, $rootScope, $routeParams, $location, service) { + $scope.jobs = []; + $scope.intervalTypes = [ + "Second", + "Minute", + "Hour", + "Day", + "Week", + "Month", + "Year", + ]; + $scope.schedule = { + jobData: { + data: { + type: "Info", + from: { + connectionId: "", + userName: "", + avatar: "", + }, + title: "value", + message: "content", + data: {}, + }, + }, + cronExpression: null, + name: null, + groupName: null, + jobName: null, + description: null, + startAt: null, + isStartNow: true, + interval: null, + intervalType: "Second", + repeatCount: null, + }; + $scope.init = function () { + $scope.getTriggers(); + $scope.getJobs(); + }; + + $scope.getSingle = async function () { + $scope.getJobs(); + $scope.getTrigger(); + }; + + $scope.getTrigger = async function () { + if ($routeParams.name) { + $rootScope.isBusy = true; + $scope.isReschedule = true; + var resp = await service.getTrigger($routeParams.name); + if (resp && resp.success) { + $scope.trigger = resp.data.trigger; + // $scope.schedule.trigger = $scope.trigger; + $scope.schedule.name = $scope.trigger.name; + $scope.schedule.jobName = $scope.trigger.jobName; + $scope.schedule.groupName = $scope.trigger.group; + $scope.schedule.interval = $scope.trigger.repeatInterval; + $scope.schedule.repeatCount = $scope.trigger.repeatCount; + if ($scope.trigger.jobDataMap.data) { + $scope.schedule.jobData = JSON.parse( + $scope.trigger.jobDataMap.data + ); + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); + } + $rootScope.isBusy = false; + $scope.$apply(); + } } - var resp = await service.filter($scope.request); + }; + + $scope.createSchedule = async function () { + $rootScope.isBusy = true; + var resp = $scope.isReschedule + ? await service.reschedule($scope.schedule) + : await service.createSchedule($scope.schedule); if (resp && resp.success) { - $scope.data = resp.data; - $.each($scope.data, function (i, data) { - $.each($scope.viewmodels, function (i, e) { - if (e.dataContentId === data.id) { - data.isHidden = true; - } - }); - }); - if ($scope.getListSuccessCallback) { - $scope.getListSuccessCallback(); - } - if ($scope.isScrollTop) { - $("html, body").animate({ scrollTop: "0px" }, 500); - } - $rootScope.isBusy = false; + $rootScope.isBusy = true; + $location.url("/admin/scheduler"); $scope.$apply(); } else { if (resp) { $rootScope.showErrors(resp.errors || ["Failed"]); } - if ($scope.getListFailCallback) { - $scope.getListFailCallback(); - } $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.loadMetadataDatabase = async function () { - var getMixDatabase = await databaseService.getByName(["Metadata"]); - let typeCol = getMixDatabase.data.columns.find( - (c) => c.systemName == "type" - ); - $scope.lstMetadata = typeCol.columnConfigurations.allowedValues; - $scope.$apply(); + $scope.updateJobData = function (content) { + try { + $scope.schedule.jobData = JSON.parse(content); + $scope.$apply(); + } catch {} }; - $scope.loadAdditionalDatabases = async function () { - let getTypes = await databaseService.getList($scope.postTypeRequest); - if (getTypes.success) { - $scope.additionalDatabases = getTypes.data.items; - $scope.additionalDatabases.splice(0, 0, { - systemName: null, - displayName: "All", - id: 0, - }); - if ($scope.request.mixDatabaseName) { - $scope.additionalDatabase = $rootScope.findObjectByKey( - $scope.additionalDatabases, - "mixDatabaseName", - $scope.request.mixDatabaseName - ); + $scope.pauseTrigger = async function (name) { + $rootScope.isBusy = true; + var resp = await service.pauseTrigger(name); + if (resp && resp.success) { + $scope.schedule = resp.data; + await $scope.getTriggers(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); } - $scope.request.mixDatabaseName = $routeParams.type || ""; + $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.getDefault = async function (type = null) { + + $scope.resumeTrigger = async function (name) { $rootScope.isBusy = true; - type = type || $routeParams.type; - var resp = await service.getDefault({ - type: type || "", - template: $routeParams.template || "", - }); - if (resp.success) { - $scope.viewmodel = resp.data; - mixDbService.initDbName($scope.viewmodel.mixDatabaseName); - if ($scope.getSingleSuccessCallback) { - $scope.getSingleSuccessCallback(); + var resp = await service.resumeTrigger(name); + if (resp && resp.success) { + $scope.schedule = resp.data; + await $scope.getTriggers(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; - // $scope.viewmodel.createdDateTime = Date.now(); - $scope.viewmodel.createdBy = $rootScope.authentication.username; - + $scope.getTriggers = async function () { + $rootScope.isBusy = true; + var resp = await service.getTriggers(); + if (resp && resp.success) { + $scope.data = resp.data; $rootScope.isBusy = false; $scope.$apply(); } else { if (resp) { - $rootScope.showErrors(resp.errors); - } - if ($scope.getSingleFailCallback) { - $scope.getSingleFailCallback(); + $rootScope.showErrors(resp.errors || ["Failed"]); } $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.preview = function (item) { - item.editUrl = "/admin/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); - }; - $scope.onSelectType = function () { - if ($scope.viewmodel) { - $scope.viewmodel.mixDatabaseName = $scope.additionalDatabase.systemName; - mixDbService.initDbName($scope.viewmodel.mixDatabaseName); - $scope.loadAdditionalData(); - } - $scope.request.additionalDatabase = - $scope.additionalDatabase.mixDatabaseName; - $scope.createUrl = `/admin/post/create?type=${$scope.request.additionalDatabase}`; - if ($routeParams.template) { - $scope.createUrl += `&template=${$routeParams.template}`; - } - if ( - $scope.additionalDatabase.mixDatabaseName && - (!$scope.viewmodel || !$scope.viewmodel.id) - ) { - $scope.getDefault($scope.request.additionalDatabase); - } - if ($scope.pageName == "postList") { - $scope.filter(); + $scope.getJobs = async function () { + $rootScope.isBusy = true; + var resp = await service.getJobs(); + if (resp && resp.success) { + $scope.jobs = resp.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); + } + $rootScope.isBusy = false; + $scope.$apply(); } }; - $scope.getListRelated = async function (pageIndex) { - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } - if ($scope.request.fromDate !== null) { - var d = new Date($scope.request.fromDate); - $scope.request.fromDate = d.toISOString(); - } - if ($scope.request.toDate !== null) { - var d = new Date($scope.request.toDate); - $scope.request.toDate = d.toISOString(); - } - var resp = await service.filter($scope.request); + $scope.deleteJob = async function (name) { + $rootScope.isBusy = true; + var resp = await service.deleteJob(name); if (resp && resp.success) { - $scope.relatedData = angular.copy(resp.data); - $scope.relatedData.items = []; - angular.forEach(resp.data.items, (element) => { - let isActive = - null != - $scope.viewmodel.postNavs.find( - (p) => p.destinationId == element.id - ); - if (!isActive) { - var obj = { - description: element.title, - destinationId: element.id, - image: element.image, - isActived: isActive, - sourceId: $scope.viewmodel.id, - specificulture: $scope.viewmodel.specificulture, - status: "Published", - }; - result.push(obj); - } - }); - resp.data.items = result; - $rootScope.isBusy = false; - $scope.$apply(); - return resp.data; + $scope.getJobs(); } else { - $rootScope.showErrors(getData.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.saveFailCallback = function () { - angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { - if (nav.isActived) { - $rootScope.decryptMixDatabase( - nav.mixDatabase.attributes, - nav.mixDatabase.postData.items - ); - } - }); - }; - $scope.saveSuccessCallback = async function () { - if ($scope.additionalData && $scope.viewmodel.mixDatabaseName) { - var creating = !$scope.additionalData.parentId; - $scope.additionalData.parentType = "Post"; - $scope.additionalData.parentId = $scope.viewmodel.id; - mixDbService.initDbName($scope.viewmodel.mixDatabaseName); - var saveResult = await mixDbService.save($scope.additionalData); - if (saveResult.success) { - $rootScope.showMessage("Additional Data Saved", "success"); - $scope.additionalData = saveResult.data; - if (creating) { - $location.url(`/admin/post/details/${$scope.viewmodel.id}`); - } - } else { - $rootScope.showErrors(result.errors); - } - // $scope.additionalData.isClone = $scope.viewmodel.isClone; - // $scope.additionalData.cultures = $scope.viewmodel.cultures; - // $scope.additionalData.intParentId = $scope.viewmodel.id; - // $scope.additionalData.parentType = "Post"; - // let result = await dataService.save($scope.additionalData); - // if (!result.success) { - // $rootScope.showErrors(result.errors); - // } else { - // $scope.additionalData = result.data; - // // $scope.saveColumns(); - // } - } - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - }; - - $scope.saveColumns = async function () { - let result = await columnService.saveMany($scope.additionalData.columns); - if (result.success) { - $rootScope.showMessage("success", "success"); - } - }; - $scope.getSingleSuccessCallback = async function () { - if (!$scope.viewmodel.id) { - $scope.viewmodel.mixDatabaseName = $routeParams.type; - } - mixDbService.initDbName($scope.viewmodel.mixDatabaseName); - await $scope.loadMetadataDatabase(); - // $scope.defaultThumbnailImgWidth = - // ngAppSettings.mixConfigurations.DefaultThumbnailImgWidth; - // $scope.defaultThumbnailImgHeight = - // ngAppSettings.mixConfigurations.DefaultThumbnailImgHeight; - - // $scope.defaultFeatureImgWidth = - // ngAppSettings.mixConfigurations.DefaultFeatureImgWidth; - // $scope.defaultFeatureImgHeight = - // ngAppSettings.mixConfigurations.DefaultFeatureImgHeight; - $scope.request.additionalDatabase = $scope.viewmodel.mixDatabaseName; - var moduleIds = $routeParams.moduleIds; - var pageIds = $routeParams.page_ids; - $scope.additionalDatabase = $rootScope.findObjectByKey( - $scope.additionalDatabases, - "systemName", - $scope.request.additionalDatabase - ); - $scope.loadAdditionalData(); - if (moduleIds) { - for (var moduleContentId of moduleIds.split(",")) { - var moduleNav = $rootScope.findObjectByKey( - $scope.viewmodel.modules, - "moduleContentId", - moduleContentId - ); - if (moduleNav) { - moduleNav.isActived = true; - } - } - } - if (pageIds) { - for (var pageId of pageIds.split(",")) { - var pageNav = $rootScope.findObjectByKey( - $scope.viewmodel.pages, - "pageId", - pageId - ); - if (pageNav) { - pageNav.isActived = true; - } - } - } - }; - $scope.loadAdditionalData = async function () { - if ($scope.viewmodel.mixDatabaseName) { - $scope.loadingData = true; - mixDbService.initDbName($scope.viewmodel.mixDatabaseName); - if ($scope.viewmodel.id) { - const getData = await mixDbService.getSingleByParent( - "Post", - $scope.viewmodel.id - ); - if (getData.success) { - $scope.additionalData = getData.data; - $scope.loadingData = false; - } - $scope.$apply(); - } else { - $scope.additionalData = { - parentType: "Post", - }; - $scope.loadingData = false; - } - } - }; - $scope.generateSeo = function () { - if ($scope.viewmodel) { - if ( - $scope.viewmodel.seoName === null || - $scope.viewmodel.seoName === "" - ) { - $scope.viewmodel.seoName = $rootScope.generateKeyword( - $scope.viewmodel.title, - "-" - ); - if ($scope.viewmodel.seoName.length > 50) { - $scope.viewmodel.seoName = - $scope.viewmodel.seoName.substring(0, 80) + "..."; - } - } - if ( - $scope.viewmodel.seoTitle === null || - $scope.viewmodel.seoTitle === "" - ) { - $scope.viewmodel.seoTitle = $scope.viewmodel.title; - } - if ( - $scope.viewmodel.seoDescription === null || - $scope.viewmodel.seoDescription === "" - ) { - $scope.viewmodel.seoDescription = $scope.viewmodel.excerpt; - } - if ( - $scope.viewmodel.seoKeywords === null || - $scope.viewmodel.seoKeywords === "" - ) { - $scope.viewmodel.seoKeywords = $scope.viewmodel.title; + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); } - } - }; - $scope.addAlias = async function () { - var getAlias = await urlAliasService.getDefault(); - if (getAlias.success) { - $scope.viewmodel.urlAliases.push(getAlias.data); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(getAlias.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.removeAliasCallback = async function (index) { - $scope.viewmodel.urlAliases.splice(index, 1); - $scope.$apply(); - }; - - $scope.validate = function () { - angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { - if (nav.isActived) { - $rootScope.encryptMixDatabase( - nav.mixDatabase.attributes, - nav.mixDatabase.postData.items - ); - } - }); - return true; - }; }, ]); "use strict"; -app.factory("PostRestService", [ - "BaseRestService", - function (baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("mix-post-content"); - var _filter = async function (request) { - var url = `${this.prefixUrl}/filter`; +app.factory("SchedulerService", [ + "AuthService", + "ApiService", + function (authService, apiService) { + var serviceFactory = {}; + serviceFactory.prefixUrl = "/scheduler"; + var _createSchedule = async function (schedule) { + var url = `${this.prefixUrl}/trigger/create`; var req = { serviceBase: this.serviceBase, method: "POST", url: url, - data: request, + data: JSON.stringify(schedule), }; return await this.getRestApiResult(req); }; - // Define more service methods here - serviceFactory.filter = _filter; - return serviceFactory; - }, -]); - -"use strict"; -app.controller("RoleController", [ - "$scope", - "$rootScope", - "$location", - "$routeParams", - "ngAppSettings", - "RestMixDatabaseDataPortalService", - "RestMixDatabaseColumnPortalService", - "RoleService", - function ( - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - dataService, - columnService, - service - ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - service - ); - $scope.role = { name: "" }; - $scope.initPermissions = async function () { - let backUrl = "/admin/role/list"; - $scope.createUrl = `/admin/mix-database-data/create?mixDatabaseName=sysPermission&dataContentId=default&guidParentId=${$scope.viewmodel.id}&parentType=Role&backUrl=${backUrl}`; - $scope.updateUrl = "/admin/mix-database-data/details"; + var _reschedule = async function (schedule) { + var url = `${this.prefixUrl}/reschedule`; + var req = { + serviceBase: this.serviceBase, + method: "POST", + url: url, + data: JSON.stringify(schedule), + }; + return await this.getRestApiResult(req); }; - - $scope.createRole = async function () { - $rootScope.isBusy = true; - var result = await service.createRole($scope.role.name); - if (result.success) { - $scope.role.name = ""; - $scope.getList(); - } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } + var _pauseTrigger = async function (name) { + var url = `${this.prefixUrl}/trigger/pause/${name}`; + var req = { + serviceBase: this.serviceBase, + method: "GET", + url: url, + }; + return await this.getRestApiResult(req); }; - }, -]); -"use strict"; -app.factory("RoleService", [ - "BaseRestService", - "ApiService", - "CommonService", - function (baseService, apiService, commonService) { - var serviceFactory = Object.create(baseService); - serviceFactory.initService("/rest/mix-account", "role", true); + var _resumeTrigger = async function (name) { + var url = `${this.prefixUrl}/trigger/resume/${name}`; + var req = { + serviceBase: this.serviceBase, + method: "GET", + url: url, + }; + return await this.getRestApiResult(req); + }; - var _getPermissions = async function () { + var _getTrigger = async function (name) { + var url = `${this.prefixUrl}/trigger/${name}`; var req = { + serviceBase: this.serviceBase, method: "GET", - url: this.prefixUrl + "/permissions", + url: url, }; - return await apiService.sendRequest(req); + return await this.getRestApiResult(req); }; - var _updatePermission = async function (permission) { + var _getTriggers = async function () { + var url = `${this.prefixUrl}/trigger`; var req = { - method: "POST", - url: this.prefixUrl + "/update-permission", - data: JSON.stringify(permission), + serviceBase: this.serviceBase, + method: "GET", + url: url, }; - return await apiService.sendRequest(req); + return await this.getRestApiResult(req); }; - var _createRole = function (name) { + var _getJobs = async function () { + var url = `${this.prefixUrl}/job`; var req = { - method: "POST", - url: this.prefixUrl + "/create", - data: JSON.stringify(name), + serviceBase: this.serviceBase, + method: "GET", + url: url, }; + return await this.getRestApiResult(req); + }; - return apiService.sendRequest(req); + var _deleteJob = async function (name) { + var url = `${this.prefixUrl}/job/${name}`; + var req = { + serviceBase: this.serviceBase, + method: "DELETE", + url: url, + }; + return await this.getRestApiResult(req); }; - serviceFactory.createRole = _createRole; - serviceFactory.getPermissions = _getPermissions; - serviceFactory.updatePermission = _updatePermission; + + var _getRestApiResult = async function (req) { + if (!authService.authentication) { + await authService.fillAuthData(); + } + if (authService.authentication) { + req.Authorization = authService.authentication.accessToken; + } + if (!req.headers) { + req.headers = { + "Content-Type": "application/json", + }; + } + req.headers.Authorization = "Bearer " + req.Authorization || ""; + + return apiService.sendRequest(req).then(function (resp) { + return resp; + }); + }; + var _parseQuery = function (req) { + var result = ""; + if (req) { + for (var key in req) { + if (angular.isObject(req.query)) { + req.query = JSON.stringify(req.query); + } + if (req.hasOwnProperty(key) && req[key]) { + if (result != "") { + result += "&"; + } + result += `${key}=${req[key]}`; + } + } + return result; + } else { + return result; + } + }; + serviceFactory.parseQuery = _parseQuery; + serviceFactory.getRestApiResult = _getRestApiResult; + serviceFactory.createSchedule = _createSchedule; + serviceFactory.reschedule = _reschedule; + serviceFactory.getJobs = _getJobs; + serviceFactory.deleteJob = _deleteJob; + serviceFactory.getTrigger = _getTrigger; + serviceFactory.getTriggers = _getTriggers; + serviceFactory.pauseTrigger = _pauseTrigger; + serviceFactory.resumeTrigger = _resumeTrigger; return serviceFactory; }, ]); "use strict"; -app.controller("SchedulerController", [ +app.controller("PostController", [ "$scope", "$rootScope", - "$routeParams", "$location", - "SchedulerService", - function ($scope, $rootScope, $routeParams, $location, service) { - $scope.jobs = []; - $scope.intervalTypes = [ - "Second", - "Minute", - "Hour", - "Day", - "Week", - "Month", - "Year", - ]; - $scope.schedule = { - jobData: { - data: { - type: "Info", - from: { - connectionId: "", - userName: "", - avatar: "", - }, - title: "value", - message: "content", - data: {}, - }, - }, - cronExpression: null, - name: null, - groupName: null, - jobName: null, - description: null, - startAt: null, - isStartNow: true, - interval: null, - intervalType: "Second", - repeatCount: null, - }; - $scope.init = function () { - $scope.getTriggers(); - $scope.getJobs(); + "$filter", + "ngAppSettings", + "$routeParams", + "PostRestService", + "UrlAliasService", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", + "RestRelatedAttributeDataPortalService", + "RestMixDatabasePortalService", + "MixDbService", + function ( + $scope, + $rootScope, + $location, + $filter, + ngAppSettings, + $routeParams, + service, + urlAliasService, + dataService, + columnService, + navService, + databaseService, + mixDbService + ) { + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + service + ); + if (!$scope.referrerUrl) { + $scope.referrerUrl = "/admin/post/list"; + } + $scope.request.searchColumns = "title"; + $scope.request.culture = $rootScope.globalSettings.defaultCulture; + $scope.request.queries = []; + $scope.defaultQuery = { + fieldName: "", + compareOperator: "Equal", + value: "", }; + $scope.viewmodelType = "post"; + $scope.additionalData = {}; + $scope.createUrl = "/admin/post/create?"; + $scope.postTypeRequest = angular.copy(ngAppSettings.request); + ($scope.postTypeRequest.searchColumns = "Type"), + ($scope.postTypeRequest.searchMethod = "Equal"), + ($scope.postTypeRequest.keyword = "AdditionalData"); - $scope.getSingle = async function () { - $scope.getJobs(); - $scope.getTrigger(); + $scope.initList = async function () { + if ($routeParams.template) { + $scope.createUrl = `${$scope.createUrl}&template=${$routeParams.template}`; + } + if ($routeParams.category) { + $scope.request.category = $routeParams.category; + } + if ($routeParams.type) { + $scope.createUrl = `${$scope.createUrl}&type=${$routeParams.type}`; + $scope.request.additionalDatabase = $routeParams.type; + $scope.request.mixDatabaseName = $routeParams.type; + } + if ($routeParams.layout) { + $scope.createUrl = `${$scope.createUrl}&layout=${$routeParams.layout}`; + } + if ($routeParams.page_ids) { + $scope.createUrl = `${$scope.createUrl}&page_ids=${$routeParams.page_ids}`; + } + $scope.pageName = "postList"; + await $scope.loadAdditionalDatabases(); + $scope.filter(); }; - $scope.getTrigger = async function () { - if ($routeParams.name) { - $rootScope.isBusy = true; - $scope.isReschedule = true; - var resp = await service.getTrigger($routeParams.name); - if (resp && resp.success) { - $scope.trigger = resp.data.trigger; - // $scope.schedule.trigger = $scope.trigger; - $scope.schedule.name = $scope.trigger.name; - $scope.schedule.jobName = $scope.trigger.jobName; - $scope.schedule.groupName = $scope.trigger.group; - $scope.schedule.interval = $scope.trigger.repeatInterval; - $scope.schedule.repeatCount = $scope.trigger.repeatCount; - if ($scope.trigger.jobDataMap.data) { - $scope.schedule.jobData = JSON.parse( - $scope.trigger.jobDataMap.data + $scope.parseQueryField = function (fieldName, value, operator = "Equal") { + return { + fieldName: fieldName, + value: value, + compareOperator: operator, + }; + }; + $scope.filter = async function (pageIndex) { + $rootScope.isBusy = true; + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } + if ($scope.request.fromDate !== null) { + var d = new Date($scope.request.fromDate); + $scope.request.fromDate = d.toISOString(); + } + if ($scope.request.toDate !== null) { + var dt = new Date($scope.request.toDate); + $scope.request.toDate = dt.toISOString(); + } + var resp = await service.filter($scope.request); + if (resp && resp.success) { + $scope.data = resp.data; + $.each($scope.data, function (i, data) { + $.each($scope.viewmodels, function (i, e) { + if (e.dataContentId === data.id) { + data.isHidden = true; + } + }); + }); + if ($scope.getListSuccessCallback) { + $scope.getListSuccessCallback(); + } + if ($scope.isScrollTop) { + $("html, body").animate({ scrollTop: "0px" }, 500); + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors || ["Failed"]); + } + if ($scope.getListFailCallback) { + $scope.getListFailCallback(); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.loadMetadataDatabase = async function () { + var getMixDatabase = await databaseService.getByName(["Metadata"]); + let typeCol = getMixDatabase.data.columns.find( + (c) => c.systemName == "type" + ); + $scope.lstMetadata = typeCol.columnConfigurations.allowedValues; + $scope.$apply(); + }; + $scope.loadAdditionalDatabases = async function () { + let getTypes = await databaseService.getList($scope.postTypeRequest); + if (getTypes.success) { + $scope.additionalDatabases = getTypes.data.items; + $scope.additionalDatabases.splice(0, 0, { + systemName: null, + displayName: "All", + id: 0, + }); + if ($scope.request.mixDatabaseName) { + $scope.additionalDatabase = $rootScope.findObjectByKey( + $scope.additionalDatabases, + "mixDatabaseName", + $scope.request.mixDatabaseName + ); + } + $scope.request.mixDatabaseName = $routeParams.type || ""; + $scope.$apply(); + } + }; + $scope.getDefault = async function (type = null) { + $rootScope.isBusy = true; + type = type || $routeParams.type; + var resp = await service.getDefault({ + type: type || "", + template: $routeParams.template || "", + }); + if (resp.success) { + $scope.viewmodel = resp.data; + mixDbService.initDbName($scope.viewmodel.mixDatabaseName); + if ($scope.getSingleSuccessCallback) { + $scope.getSingleSuccessCallback(); + } + + // $scope.viewmodel.createdDateTime = Date.now(); + $scope.viewmodel.createdBy = $rootScope.authentication.username; + + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + if ($scope.getSingleFailCallback) { + $scope.getSingleFailCallback(); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.preview = function (item) { + item.editUrl = "/admin/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); + }; + $scope.onSelectType = function () { + if ($scope.viewmodel) { + $scope.viewmodel.mixDatabaseName = $scope.additionalDatabase.systemName; + mixDbService.initDbName($scope.viewmodel.mixDatabaseName); + $scope.loadAdditionalData(); + } + $scope.request.additionalDatabase = + $scope.additionalDatabase.mixDatabaseName; + $scope.createUrl = `/admin/post/create?type=${$scope.request.additionalDatabase}`; + if ($routeParams.template) { + $scope.createUrl += `&template=${$routeParams.template}`; + } + if ( + $scope.additionalDatabase.mixDatabaseName && + (!$scope.viewmodel || !$scope.viewmodel.id) + ) { + $scope.getDefault($scope.request.additionalDatabase); + } + if ($scope.pageName == "postList") { + $scope.filter(); + } + }; + $scope.getListRelated = async function (pageIndex) { + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } + if ($scope.request.fromDate !== null) { + var d = new Date($scope.request.fromDate); + $scope.request.fromDate = d.toISOString(); + } + if ($scope.request.toDate !== null) { + var d = new Date($scope.request.toDate); + $scope.request.toDate = d.toISOString(); + } + var resp = await service.filter($scope.request); + if (resp && resp.success) { + $scope.relatedData = angular.copy(resp.data); + $scope.relatedData.items = []; + angular.forEach(resp.data.items, (element) => { + let isActive = + null != + $scope.viewmodel.postNavs.find( + (p) => p.destinationId == element.id ); + if (!isActive) { + var obj = { + description: element.title, + destinationId: element.id, + image: element.image, + isActived: isActive, + sourceId: $scope.viewmodel.id, + specificulture: $scope.viewmodel.specificulture, + status: "Published", + }; + result.push(obj); + } + }); + resp.data.items = result; + $rootScope.isBusy = false; + $scope.$apply(); + return resp.data; + } else { + $rootScope.showErrors(getData.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.saveFailCallback = function () { + angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { + if (nav.isActived) { + $rootScope.decryptMixDatabase( + nav.mixDatabase.attributes, + nav.mixDatabase.postData.items + ); + } + }); + }; + $scope.saveSuccessCallback = async function () { + if ($scope.additionalData && $scope.viewmodel.mixDatabaseName) { + var creating = !$scope.additionalData.parentId; + $scope.additionalData.parentType = "Post"; + $scope.additionalData.parentId = $scope.viewmodel.id; + mixDbService.initDbName($scope.viewmodel.mixDatabaseName); + var saveResult = await mixDbService.save($scope.additionalData); + if (saveResult.success) { + $rootScope.showMessage("Additional Data Saved", "success"); + $scope.additionalData = saveResult.data; + if (creating) { + $location.url(`/admin/post/details/${$scope.viewmodel.id}`); + } + } else { + $rootScope.showErrors(result.errors); + } + // $scope.additionalData.isClone = $scope.viewmodel.isClone; + // $scope.additionalData.cultures = $scope.viewmodel.cultures; + // $scope.additionalData.intParentId = $scope.viewmodel.id; + // $scope.additionalData.parentType = "Post"; + // let result = await dataService.save($scope.additionalData); + // if (!result.success) { + // $rootScope.showErrors(result.errors); + // } else { + // $scope.additionalData = result.data; + // // $scope.saveColumns(); + // } + } + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + }; + + $scope.saveColumns = async function () { + let result = await columnService.saveMany($scope.additionalData.columns); + if (result.success) { + $rootScope.showMessage("success", "success"); + } + }; + $scope.getSingleSuccessCallback = async function () { + if (!$scope.viewmodel.id) { + $scope.viewmodel.mixDatabaseName = $routeParams.type; + } + mixDbService.initDbName($scope.viewmodel.mixDatabaseName); + await $scope.loadMetadataDatabase(); + // $scope.defaultThumbnailImgWidth = + // ngAppSettings.mixConfigurations.DefaultThumbnailImgWidth; + // $scope.defaultThumbnailImgHeight = + // ngAppSettings.mixConfigurations.DefaultThumbnailImgHeight; + + // $scope.defaultFeatureImgWidth = + // ngAppSettings.mixConfigurations.DefaultFeatureImgWidth; + // $scope.defaultFeatureImgHeight = + // ngAppSettings.mixConfigurations.DefaultFeatureImgHeight; + $scope.request.additionalDatabase = $scope.viewmodel.mixDatabaseName; + var moduleIds = $routeParams.moduleIds; + var pageIds = $routeParams.page_ids; + $scope.additionalDatabase = $rootScope.findObjectByKey( + $scope.additionalDatabases, + "systemName", + $scope.request.additionalDatabase + ); + $scope.loadAdditionalData(); + if (moduleIds) { + for (var moduleContentId of moduleIds.split(",")) { + var moduleNav = $rootScope.findObjectByKey( + $scope.viewmodel.modules, + "moduleContentId", + moduleContentId + ); + if (moduleNav) { + moduleNav.isActived = true; + } + } + } + if (pageIds) { + for (var pageId of pageIds.split(",")) { + var pageNav = $rootScope.findObjectByKey( + $scope.viewmodel.pages, + "pageId", + pageId + ); + if (pageNav) { + pageNav.isActived = true; + } + } + } + }; + $scope.loadAdditionalData = async function () { + if ($scope.viewmodel.mixDatabaseName) { + $scope.loadingData = true; + mixDbService.initDbName($scope.viewmodel.mixDatabaseName); + if ($scope.viewmodel.id) { + const getData = await mixDbService.getSingleByParent( + "Post", + $scope.viewmodel.id + ); + if (getData.success) { + $scope.additionalData = getData.data; + $scope.loadingData = false; } - $rootScope.isBusy = false; $scope.$apply(); } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); - } - $rootScope.isBusy = false; - $scope.$apply(); + $scope.additionalData = { + parentType: "Post", + }; + $scope.loadingData = false; } } }; - - $scope.createSchedule = async function () { - $rootScope.isBusy = true; - var resp = $scope.isReschedule - ? await service.reschedule($scope.schedule) - : await service.createSchedule($scope.schedule); - if (resp && resp.success) { - $rootScope.isBusy = true; - $location.url("/admin/scheduler"); - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); + $scope.generateSeo = function () { + if ($scope.viewmodel) { + if ( + $scope.viewmodel.seoName === null || + $scope.viewmodel.seoName === "" + ) { + $scope.viewmodel.seoName = $rootScope.generateKeyword( + $scope.viewmodel.title, + "-" + ); + if ($scope.viewmodel.seoName.length > 50) { + $scope.viewmodel.seoName = + $scope.viewmodel.seoName.substring(0, 80) + "..."; + } } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.updateJobData = function (content) { - try { - $scope.schedule.jobData = JSON.parse(content); - $scope.$apply(); - } catch {} - }; - $scope.pauseTrigger = async function (name) { - $rootScope.isBusy = true; - var resp = await service.pauseTrigger(name); - if (resp && resp.success) { - $scope.schedule = resp.data; - await $scope.getTriggers(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); + if ( + $scope.viewmodel.seoTitle === null || + $scope.viewmodel.seoTitle === "" + ) { + $scope.viewmodel.seoTitle = $scope.viewmodel.title; } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - - $scope.resumeTrigger = async function (name) { - $rootScope.isBusy = true; - var resp = await service.resumeTrigger(name); - if (resp && resp.success) { - $scope.schedule = resp.data; - await $scope.getTriggers(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); + if ( + $scope.viewmodel.seoDescription === null || + $scope.viewmodel.seoDescription === "" + ) { + $scope.viewmodel.seoDescription = $scope.viewmodel.excerpt; } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - - $scope.getTriggers = async function () { - $rootScope.isBusy = true; - var resp = await service.getTriggers(); - if (resp && resp.success) { - $scope.data = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); + if ( + $scope.viewmodel.seoKeywords === null || + $scope.viewmodel.seoKeywords === "" + ) { + $scope.viewmodel.seoKeywords = $scope.viewmodel.title; } - $rootScope.isBusy = false; - $scope.$apply(); } }; - $scope.getJobs = async function () { - $rootScope.isBusy = true; - var resp = await service.getJobs(); - if (resp && resp.success) { - $scope.jobs = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); - } + $scope.addAlias = async function () { + var getAlias = await urlAliasService.getDefault(); + if (getAlias.success) { + $scope.viewmodel.urlAliases.push(getAlias.data); $rootScope.isBusy = false; $scope.$apply(); - } - }; - $scope.deleteJob = async function (name) { - $rootScope.isBusy = true; - var resp = await service.deleteJob(name); - if (resp && resp.success) { - $scope.getJobs(); } else { - if (resp) { - $rootScope.showErrors(resp.errors || ["Failed"]); - } + $rootScope.showErrors(getAlias.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - }, -]); - -"use strict"; -app.factory("SchedulerService", [ - "AuthService", - "ApiService", - function (authService, apiService) { - var serviceFactory = {}; - serviceFactory.prefixUrl = "/scheduler"; - var _createSchedule = async function (schedule) { - var url = `${this.prefixUrl}/trigger/create`; - var req = { - serviceBase: this.serviceBase, - method: "POST", - url: url, - data: JSON.stringify(schedule), - }; - return await this.getRestApiResult(req); - }; - var _reschedule = async function (schedule) { - var url = `${this.prefixUrl}/reschedule`; - var req = { - serviceBase: this.serviceBase, - method: "POST", - url: url, - data: JSON.stringify(schedule), - }; - return await this.getRestApiResult(req); - }; - var _pauseTrigger = async function (name) { - var url = `${this.prefixUrl}/trigger/pause/${name}`; - var req = { - serviceBase: this.serviceBase, - method: "GET", - url: url, - }; - return await this.getRestApiResult(req); - }; - - var _resumeTrigger = async function (name) { - var url = `${this.prefixUrl}/trigger/resume/${name}`; - var req = { - serviceBase: this.serviceBase, - method: "GET", - url: url, - }; - return await this.getRestApiResult(req); - }; - - var _getTrigger = async function (name) { - var url = `${this.prefixUrl}/trigger/${name}`; - var req = { - serviceBase: this.serviceBase, - method: "GET", - url: url, - }; - return await this.getRestApiResult(req); - }; - - var _getTriggers = async function () { - var url = `${this.prefixUrl}/trigger`; - var req = { - serviceBase: this.serviceBase, - method: "GET", - url: url, - }; - return await this.getRestApiResult(req); - }; - var _getJobs = async function () { - var url = `${this.prefixUrl}/job`; - var req = { - serviceBase: this.serviceBase, - method: "GET", - url: url, - }; - return await this.getRestApiResult(req); - }; - - var _deleteJob = async function (name) { - var url = `${this.prefixUrl}/job/${name}`; - var req = { - serviceBase: this.serviceBase, - method: "DELETE", - url: url, - }; - return await this.getRestApiResult(req); + $scope.removeAliasCallback = async function (index) { + $scope.viewmodel.urlAliases.splice(index, 1); + $scope.$apply(); }; - var _getRestApiResult = async function (req) { - if (!authService.authentication) { - await authService.fillAuthData(); - } - if (authService.authentication) { - req.Authorization = authService.authentication.accessToken; - } - if (!req.headers) { - req.headers = { - "Content-Type": "application/json", - }; - } - req.headers.Authorization = "Bearer " + req.Authorization || ""; - - return apiService.sendRequest(req).then(function (resp) { - return resp; - }); - }; - var _parseQuery = function (req) { - var result = ""; - if (req) { - for (var key in req) { - if (angular.isObject(req.query)) { - req.query = JSON.stringify(req.query); - } - if (req.hasOwnProperty(key) && req[key]) { - if (result != "") { - result += "&"; - } - result += `${key}=${req[key]}`; - } + $scope.validate = function () { + angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { + if (nav.isActived) { + $rootScope.encryptMixDatabase( + nav.mixDatabase.attributes, + nav.mixDatabase.postData.items + ); } - return result; - } else { - return result; - } + }); + return true; }; - serviceFactory.parseQuery = _parseQuery; - serviceFactory.getRestApiResult = _getRestApiResult; - serviceFactory.createSchedule = _createSchedule; - serviceFactory.reschedule = _reschedule; - serviceFactory.getJobs = _getJobs; - serviceFactory.deleteJob = _deleteJob; - serviceFactory.getTrigger = _getTrigger; - serviceFactory.getTriggers = _getTriggers; - serviceFactory.pauseTrigger = _pauseTrigger; - serviceFactory.resumeTrigger = _resumeTrigger; + }, +]); + +"use strict"; +app.factory("PostRestService", [ + "BaseRestService", + function (baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("mix-post-content"); + var _filter = async function (request) { + var url = `${this.prefixUrl}/filter`; + var req = { + serviceBase: this.serviceBase, + method: "POST", + url: url, + data: request, + }; + return await this.getRestApiResult(req); + }; + // Define more service methods here + serviceFactory.filter = _filter; return serviceFactory; }, ]); @@ -5547,225 +5548,78 @@ app.controller("TemplateController", [ $scope.$apply(); } }; - $scope.getList = async function (pageIndex, themeId) { - $scope.request.themeId = themeId || $routeParams.themeId; - $scope.request.folderType = $routeParams.folderType; - $scope.request.status = null; - $scope.folderType = $routeParams.folderType; - if ($scope.folderType) { - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } - if ($scope.request.fromDate !== null) { - var df = new Date($scope.request.fromDate); - $scope.request.fromDate = df.toISOString(); - } - if ($scope.request.toDate !== null) { - var dt = new Date($scope.request.toDate); - $scope.request.toDate = dt.toISOString(); - } - var resp = await service.getList($scope.request, [$scope.themeId]); - if (resp && resp.success) { - $scope.data = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - } else { - $rootScope.isBusy = false; - } - }; - $scope.updateTemplateContent = function (content) { - $scope.viewmodel.content = content; - }; - $scope.updateStyleContent = function (content) { - $scope.viewmodel.scripts = content; - }; - $scope.updateScriptContent = function (content) { - $scope.viewmodel.styles = content; - }; - $scope.joinRoom = function () { - $scope.connection.invoke("JoinRoom", $scope.room, $scope.user); - }; - $scope.receiveMessage = function (msg) { - switch (msg.type) { - case "MemberList": - $scope.members = msg.data; - $scope.initMembersData(); - $scope.canEdit = $scope.members.length == 1; - if (!$scope.canEdit) { - $scope.errors = [ - "Cannot modify if there is another user opening this template", - ]; - } else { - $scope.errors = []; - } - $scope.$apply(); - break; - - default: - break; - } - console.log(msg); - }; - $scope.initMembersData = function () { - angular.forEach($scope.members, function (e) { - if (!e.Avatar) { - e.Avatar = "/mix-app/assets/img/user.png"; - } - }); - }; - }, -]); - -"use strict"; -app.controller("ThemeController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "ThemeService", - "ApiService", - "CommonService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - $location, - service, - commonService - ) { - BaseRestCtrl.call( - this, - $scope, - $rootScope, - $location, - $routeParams, - ngAppSettings, - service - ); - $scope.exportData = null; - $scope.exportThemeDto = { - isIncludeAssets: true, - isIncludeTemplates: true, - isIncludeConfigurations: true, - isIncludePermissions: true, - cultureIds: [], - content: { - pageIds: [], - pageContentIds: [], - postIds: [], - postContentIds: [], - moduleIds: [], - moduleContentIds: [], - mixDatabaseIds: [], - }, - associations: { - pageIds: [], - pageContentIds: [], - postIds: [], - postContentIds: [], - moduleIds: [], - moduleContentIds: [], - mixDatabaseIds: [], - }, - }; - - $scope.getSingleSuccessCallback = function () { - $scope.assets = null; - $scope.theme = null; - }; - - $scope.syncTemplates = async function (id) { - $rootScope.isBusy = true; - var response = await service.syncTemplates(id); - if (response.success) { - $scope.viewmodel = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.extract = async function () { - $rootScope.isBusy = true; - var frm = new FormData(); - var url = "/rest/mix-tenancy/setup/extract-theme"; - $scope.data.isCreateDefault = $scope.themeType === "materialkit"; - $rootScope.isBusy = true; - // Looping over all files and add it to FormData object - frm.append("theme", theme); - // Adding one more key to FormData object - frm.append("model", angular.toJson($scope.data)); - var response = await service.ajaxSubmitForm(frm, url); - $rootScope.isBusy = false; - if (response.success) { - $rootScope.goToPath("/init/step4"); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.export = async function () { - $scope.exportThemeDto.themeId = $routeParams.id; - $rootScope.isBusy = true; - var response = await service.export($scope.exportThemeDto); - - if (response.success) { - $rootScope.isBusy = false; - window.open(response.data, "_blank"); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.saveSuccessCallback = function () { - apiService.getAllSettings().then(function () { - // $location.path("/admin/theme/list"); - $rootScope.isBusy = false; - $scope.$apply(); - }); - }; - $scope.removeCallback = function () { - apiService.getAllSettings().then(function () { - $location.path("/admin/theme/list"); - }); - }; - - $scope.getExportData = async function () { - var id = $routeParams.id; - var resp = await service.getExportData(id); - if (resp && resp.success) { - $scope.exportData = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; + $scope.getList = async function (pageIndex, themeId) { + $scope.request.themeId = themeId || $routeParams.themeId; + $scope.request.folderType = $routeParams.folderType; + $scope.request.status = null; + $scope.folderType = $routeParams.folderType; + if ($scope.folderType) { + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } + if ($scope.request.fromDate !== null) { + var df = new Date($scope.request.fromDate); + $scope.request.fromDate = df.toISOString(); + } + if ($scope.request.toDate !== null) { + var dt = new Date($scope.request.toDate); + $scope.request.toDate = dt.toISOString(); + } + var resp = await service.getList($scope.request, [$scope.themeId]); + if (resp && resp.success) { + $scope.data = resp.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + } else { + $rootScope.isBusy = false; + } + }; + $scope.updateTemplateContent = function (content) { + $scope.viewmodel.content = content; + }; + $scope.updateStyleContent = function (content) { + $scope.viewmodel.scripts = content; + }; + $scope.updateScriptContent = function (content) { + $scope.viewmodel.styles = content; + }; + $scope.joinRoom = function () { + $scope.connection.invoke("JoinRoom", $scope.room, $scope.user); + }; + $scope.receiveMessage = function (msg) { + switch (msg.type) { + case "MemberList": + $scope.members = msg.data; + $scope.initMembersData(); + $scope.canEdit = $scope.members.length == 1; + if (!$scope.canEdit) { + $scope.errors = [ + "Cannot modify if there is another user opening this template", + ]; + } else { + $scope.errors = []; + } + $scope.$apply(); + break; - $scope.generateSEO = function () { - $scope.viewmodel.name = $rootScope.generateKeyword( - $scope.viewmodel.title, - "-" - ); + default: + break; + } + console.log(msg); + }; + $scope.initMembersData = function () { + angular.forEach($scope.members, function (e) { + if (!e.Avatar) { + e.Avatar = "/mix-app/assets/img/user.png"; + } + }); }; }, ]); @@ -5819,80 +5673,71 @@ app.factory("TenantRestService", [ ]); "use strict"; -app.controller("ThemeImportController", [ +app.controller("ThemeController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", + "ThemeService", "ApiService", - "TenancyService", + "CommonService", function ( $scope, $rootScope, ngAppSettings, $routeParams, $location, - apiService, - tenancyService + service, + commonService ) { - $scope.importData = null; - $scope.init = function () {}; + BaseRestCtrl.call( + this, + $scope, + $rootScope, + $location, + $routeParams, + ngAppSettings, + service + ); + $scope.exportData = null; + $scope.exportThemeDto = { + isIncludeAssets: true, + isIncludeTemplates: true, + isIncludeConfigurations: true, + isIncludePermissions: true, + cultureIds: [], + content: { + pageIds: [], + pageContentIds: [], + postIds: [], + postContentIds: [], + moduleIds: [], + moduleContentIds: [], + mixDatabaseIds: [], + }, + associations: { + pageIds: [], + pageContentIds: [], + postIds: [], + postContentIds: [], + moduleIds: [], + moduleContentIds: [], + mixDatabaseIds: [], + }, + }; + $scope.getSingleSuccessCallback = function () { $scope.assets = null; $scope.theme = null; }; - $scope.submit = async function () { - $scope.form = document.getElementById("form-portal"); - let theme = $scope.form["theme"].files[0]; - if (theme) { - await $scope.extract(theme); - document.getElementById("form-portal")["theme"].value = ""; - } else { - $scope.import(); - } - }; - $scope.extract = async function (theme) { - $rootScope.isBusy = true; - var frm = new FormData(); - var url = "/rest/mix-tenancy/setup/extract-theme"; - $rootScope.isBusy = true; - // Looping over all files and add it to FormData object - frm.append("theme", theme); - // Adding one more key to FormData object - frm.append("model", angular.toJson($scope.data)); - var response = await apiService.ajaxSubmitForm(frm, url); - $rootScope.isBusy = false; - if (response.success) { - var getData = await $scope.loadTheme(); - if (getData.success) { - $scope.importThemeDto = getData.data; - $rootScope.isBusy = false; - $scope.$apply(); - } - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - - $scope.loadTheme = async function () { - var req = { - method: "GET", - url: "/rest/mix-tenancy/setup/load-theme", - }; - return await apiService.sendRequest(req); - }; - $scope.import = async function () { - $scope.importThemeDto.themeId = $routeParams.id; + $scope.syncTemplates = async function (id) { $rootScope.isBusy = true; - var response = await tenancyService.import($scope.importThemeDto); - + var response = await service.syncTemplates(id); if (response.success) { + $scope.viewmodel = response.data; $rootScope.isBusy = false; - window.open("/", "_blank"); $scope.$apply(); } else { $rootScope.showErrors(response.errors); @@ -5900,54 +5745,20 @@ app.controller("ThemeImportController", [ $scope.$apply(); } }; - }, -]); - -"use strict"; -app.controller("UrlAliasController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "UrlAliasService", - "ApiService", - "CommonService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - $location, - service, - apiService, - commonService - ) { - BaseCtrl.call( - this, - $scope, - $rootScope, - $routeParams, - ngAppSettings, - service - ); - $scope.cates = ["Site", "System"]; - $scope.others = []; - $scope.mixConfigurations = $rootScope.globalSettings; - $scope.pageId = $routeParams.id; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.getList = async function () { + $scope.extract = async function () { $rootScope.isBusy = true; - var id = $routeParams.id; - $scope.request.query = "&page_id=" + id; - var response = await service.getList($scope.request); - $scope.canDrag = - $scope.request.orderBy !== "Priority" || - $scope.request.direction !== "0"; + var frm = new FormData(); + var url = "/rest/mix-tenancy/setup/extract-theme"; + $scope.data.isCreateDefault = $scope.themeType === "materialkit"; + $rootScope.isBusy = true; + // Looping over all files and add it to FormData object + frm.append("theme", theme); + // Adding one more key to FormData object + frm.append("model", angular.toJson($scope.data)); + var response = await service.ajaxSubmitForm(frm, url); + $rootScope.isBusy = false; if (response.success) { - $scope.data = response.data; - $rootScope.isBusy = false; + $rootScope.goToPath("/init/step4"); $scope.$apply(); } else { $rootScope.showErrors(response.errors); @@ -5955,47 +5766,39 @@ app.controller("UrlAliasController", [ $scope.$apply(); } }; - $scope.remove = function (id) { - $rootScope.showConfirm( - $scope, - "removeConfirmed", - [id], - null, - "Remove", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - - $scope.removeConfirmed = async function (id) { - $rootScope.isBusy = true; - var result = await service.delete(id); - if (result.success) { - if ($scope.removeCallback) { - $rootScope.executeFunctionByName( - "removeCallback", - $scope.removeCallbackArgs, - $scope - ); - } - $scope.getList(); + $scope.export = async function () { + $scope.exportThemeDto.themeId = $routeParams.id; + $rootScope.isBusy = true; + var response = await service.export($scope.exportThemeDto); + + if (response.success) { + $rootScope.isBusy = false; + window.open(response.data, "_blank"); + $scope.$apply(); } else { - $rootScope.showErrors(result.errors); + $rootScope.showErrors(response.errors); $rootScope.isBusy = false; $scope.$apply(); } }; + $scope.saveSuccessCallback = function () { + apiService.getAllSettings().then(function () { + // $location.path("/admin/theme/list"); + $rootScope.isBusy = false; + $scope.$apply(); + }); + }; + $scope.removeCallback = function () { + apiService.getAllSettings().then(function () { + $location.path("/admin/theme/list"); + }); + }; - $scope.updateInfos = async function (index) { - $scope.data.items.splice(index, 1); - $rootScope.isBusy = true; - var startIndex = $scope.data.items[0].priority - 1; - for (var i = 0; i < $scope.data.items.length; i++) { - $scope.data.items[i].priority = startIndex + i + 1; - } - var resp = await service.updateInfos($scope.data.items); + $scope.getExportData = async function () { + var id = $routeParams.id; + var resp = await service.getExportData(id); if (resp && resp.success) { - $scope.activedPage = resp.data; - $rootScope.showMessage("success", "success"); + $scope.exportData = resp.data; $rootScope.isBusy = false; $scope.$apply(); } else { @@ -6006,29 +5809,98 @@ app.controller("UrlAliasController", [ $scope.$apply(); } }; + + $scope.generateSEO = function () { + $scope.viewmodel.name = $rootScope.generateKeyword( + $scope.viewmodel.title, + "-" + ); + }; }, ]); "use strict"; -app.factory("UrlAliasService", [ +app.controller("ThemeImportController", [ + "$scope", "$rootScope", + "ngAppSettings", + "$routeParams", + "$location", "ApiService", - "CommonService", - "BaseRestService", - function ($rootScope, apiService, commonService, baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.initService("/rest/mix-library", "mix-url-alias"); + "TenancyService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + $location, + apiService, + tenancyService + ) { + $scope.importData = null; + $scope.init = function () {}; + $scope.getSingleSuccessCallback = function () { + $scope.assets = null; + $scope.theme = null; + }; + $scope.submit = async function () { + $scope.form = document.getElementById("form-portal"); + let theme = $scope.form["theme"].files[0]; + if (theme) { + await $scope.extract(theme); + document.getElementById("form-portal")["theme"].value = ""; + } else { + $scope.import(); + } + }; + $scope.extract = async function (theme) { + $rootScope.isBusy = true; + var frm = new FormData(); + var url = "/rest/mix-tenancy/setup/extract-theme"; + $rootScope.isBusy = true; + // Looping over all files and add it to FormData object + frm.append("theme", theme); + // Adding one more key to FormData object + frm.append("model", angular.toJson($scope.data)); + var response = await apiService.ajaxSubmitForm(frm, url); + $rootScope.isBusy = false; + if (response.success) { + var getData = await $scope.loadTheme(); + if (getData.success) { + $scope.importThemeDto = getData.data; + $rootScope.isBusy = false; + $scope.$apply(); + } + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; - var _updateInfos = async function (pages) { + $scope.loadTheme = async function () { var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), + method: "GET", + url: "/rest/mix-tenancy/setup/load-theme", }; return await apiService.sendRequest(req); }; - serviceFactory.updateInfos = _updateInfos; - return serviceFactory; + + $scope.import = async function () { + $scope.importThemeDto.themeId = $routeParams.id; + $rootScope.isBusy = true; + var response = await tenancyService.import($scope.importThemeDto); + + if (response.success) { + $rootScope.isBusy = false; + window.open("/", "_blank"); + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; }, ]); @@ -6450,6 +6322,135 @@ app.factory("UserServices", [ }, ]); +"use strict"; +app.controller("UrlAliasController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "$location", + "UrlAliasService", + "ApiService", + "CommonService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + $location, + service, + apiService, + commonService + ) { + BaseCtrl.call( + this, + $scope, + $rootScope, + $routeParams, + ngAppSettings, + service + ); + $scope.cates = ["Site", "System"]; + $scope.others = []; + $scope.mixConfigurations = $rootScope.globalSettings; + $scope.pageId = $routeParams.id; + $scope.canDrag = + $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; + $scope.getList = async function () { + $rootScope.isBusy = true; + var id = $routeParams.id; + $scope.request.query = "&page_id=" + id; + var response = await service.getList($scope.request); + $scope.canDrag = + $scope.request.orderBy !== "Priority" || + $scope.request.direction !== "0"; + if (response.success) { + $scope.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.remove = function (id) { + $rootScope.showConfirm( + $scope, + "removeConfirmed", + [id], + null, + "Remove", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + $scope.removeConfirmed = async function (id) { + $rootScope.isBusy = true; + var result = await service.delete(id); + if (result.success) { + if ($scope.removeCallback) { + $rootScope.executeFunctionByName( + "removeCallback", + $scope.removeCallbackArgs, + $scope + ); + } + $scope.getList(); + } else { + $rootScope.showErrors(result.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.updateInfos = async function (index) { + $scope.data.items.splice(index, 1); + $rootScope.isBusy = true; + var startIndex = $scope.data.items[0].priority - 1; + for (var i = 0; i < $scope.data.items.length; i++) { + $scope.data.items[i].priority = startIndex + i + 1; + } + var resp = await service.updateInfos($scope.data.items); + if (resp && resp.success) { + $scope.activedPage = resp.data; + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, +]); + +"use strict"; +app.factory("UrlAliasService", [ + "$rootScope", + "ApiService", + "CommonService", + "BaseRestService", + function ($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.initService("/rest/mix-library", "mix-url-alias"); + + var _updateInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-infos", + data: JSON.stringify(pages), + }; + return await apiService.sendRequest(req); + }; + serviceFactory.updateInfos = _updateInfos; + return serviceFactory; + }, +]); + "use strict"; function PageDetailsController($scope, $element, $attrs) { var ctrl = this; @@ -6685,22 +6686,6 @@ modules.component("roleAssociations", { ], }); -app.component("appSettingsAuth", { - templateUrl: - "/mix-app/views/app-portal/pages/app-settings/components/auth/view.html", - controller: [ - "ngAppSettings", - function (ngAppSettings) { - var ctrl = this; - }, - ], - bindings: { - appSettings: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - app.component("appSettingsDefault", { templateUrl: "/mix-app/views/app-portal/pages/app-settings/components/default/view.html", @@ -6745,6 +6730,22 @@ app.component("appSettingsDefault", { }, }); +app.component("appSettingsAuth", { + templateUrl: + "/mix-app/views/app-portal/pages/app-settings/components/auth/view.html", + controller: [ + "ngAppSettings", + function (ngAppSettings) { + var ctrl = this; + }, + ], + bindings: { + appSettings: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + app.component("appSettingsGeneral", { templateUrl: "/mix-app/views/app-portal/pages/app-settings/components/general/view.html", @@ -6845,16 +6846,6 @@ modules.component("portalMenus", { ], }); -app.component("customerMain", { - templateUrl: - "/mix-app/views/app-portal/pages/customer/components/main/customer-main.html", - bindings: { - customer: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - app.component("appSettingsSmtp", { templateUrl: "/mix-app/views/app-portal/pages/app-settings/components/smtp/view.html", @@ -6869,38 +6860,9 @@ app.component("appSettingsSmtp", { }, }); -app.component("customerOrders", { +app.component("customerMain", { templateUrl: - "/mix-app/views/app-portal/pages/customer/components/orders/customer-orders.html", - controller: [ - "$rootScope", - "OrderServices", - function ($rootScope, orderServices) { - var ctrl = this; - ctrl.removeOrder = function (id) { - $rootScope.showConfirm( - ctrl, - "removeOrderConfirmed", - [id], - null, - "Remove Order", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - - ctrl.removeOrderConfirmed = async function (id) { - var result = await orderServices.removeOrder(id); - if (result.success) { - $rootScope.showMessage("success", "success"); - window.top.location = window.top.location.href; - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - }, - ], + "/mix-app/views/app-portal/pages/customer/components/main/customer-main.html", bindings: { customer: "=", onDelete: "&", @@ -6987,23 +6949,43 @@ app.component("moduleMain", { }, }); -app.component("moduleAdvanced", { +app.component("customerOrders", { templateUrl: - "/mix-app/views/app-portal/pages/module/components/module-advanced/view.html", - bindings: { - model: "=", - additionalData: "=", - }, + "/mix-app/views/app-portal/pages/customer/components/orders/customer-orders.html", controller: [ "$rootScope", - function ($rootScope) { + "OrderServices", + function ($rootScope, orderServices) { var ctrl = this; - ctrl.mixConfigurations = $rootScope.globalSettings; - ctrl.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; + ctrl.removeOrder = function (id) { + $rootScope.showConfirm( + ctrl, + "removeOrderConfirmed", + [id], + null, + "Remove Order", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + ctrl.removeOrderConfirmed = async function (id) { + var result = await orderServices.removeOrder(id); + if (result.success) { + $rootScope.showMessage("success", "success"); + window.top.location = window.top.location.href; + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } }; }, ], + bindings: { + customer: "=", + onDelete: "&", + onUpdate: "&", + }, }); app.component("moduleContent", { @@ -7147,49 +7129,6 @@ app.component("pageGeneral", { }, }); -app.component("pageMain", { - templateUrl: "/mix-app/views/app-portal/pages/page/components/main/main.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - function ($rootScope, $scope) { - var ctrl = this; - ctrl.mixConfigurations = $rootScope.globalSettings; - // ctrl.setPageType = function (type) { - // ctrl.page.type = $index; - // } - ctrl.generateSeo = function () { - if (ctrl.page) { - if (ctrl.page.seoName === null || ctrl.page.seoName === "") { - ctrl.page.seoName = $rootScope.generateKeyword( - ctrl.page.title, - "-" - ); - } - if (ctrl.page.seoTitle === null || ctrl.page.seoTitle === "") { - ctrl.page.seoTitle = ctrl.page.title; - } - if ( - ctrl.page.seoDescription === null || - ctrl.page.seoDescription === "" - ) { - ctrl.page.seoDescription = ctrl.page.excerpt; - } - if (ctrl.page.seoKeywords === null || ctrl.page.seoKeywords === "") { - ctrl.page.seoKeywords = ctrl.page.title; - } - } - }; - }, - ], - bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - app.component("pageModules", { templateUrl: "/mix-app/views/app-portal/pages/page/components/modules/modules.html", @@ -7256,6 +7195,49 @@ app.component("pageAdvanced", { ], }); +app.component("pageMain", { + templateUrl: "/mix-app/views/app-portal/pages/page/components/main/main.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.mixConfigurations = $rootScope.globalSettings; + // ctrl.setPageType = function (type) { + // ctrl.page.type = $index; + // } + ctrl.generateSeo = function () { + if (ctrl.page) { + if (ctrl.page.seoName === null || ctrl.page.seoName === "") { + ctrl.page.seoName = $rootScope.generateKeyword( + ctrl.page.title, + "-" + ); + } + if (ctrl.page.seoTitle === null || ctrl.page.seoTitle === "") { + ctrl.page.seoTitle = ctrl.page.title; + } + if ( + ctrl.page.seoDescription === null || + ctrl.page.seoDescription === "" + ) { + ctrl.page.seoDescription = ctrl.page.excerpt; + } + if (ctrl.page.seoKeywords === null || ctrl.page.seoKeywords === "") { + ctrl.page.seoKeywords = ctrl.page.title; + } + } + }; + }, + ], + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + app.component("pageContent", { templateUrl: "/mix-app/views/app-portal/pages/page/components/page-content/view.html", @@ -7326,6 +7308,25 @@ app.component("pageParents", { }, }); +app.component("moduleAdvanced", { + templateUrl: + "/mix-app/views/app-portal/pages/module/components/module-advanced/view.html", + bindings: { + model: "=", + additionalData: "=", + }, + controller: [ + "$rootScope", + function ($rootScope) { + var ctrl = this; + ctrl.mixConfigurations = $rootScope.globalSettings; + ctrl.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; + }; + }, + ], +}); + app.component("pagePlugPlay", { templateUrl: "/mix-app/views/app-portal/pages/page/components/plug-play/plug-play.html", @@ -7428,16 +7429,6 @@ app.component("permissionMain", { }, }); -app.component("permissionParents", { - templateUrl: - "/mix-app/views/app-portal/pages/permission/components/parents/parents.html", - bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - app.component("permissionPlugPlay", { templateUrl: "/mix-app/views/app-portal/pages/permission/components/plug-play/plug-play.html", @@ -7537,6 +7528,47 @@ app.component("permissionPlugPlay", { ], }); +modules.component("rolePageNav", { + templateUrl: + "/mix-app/views/app-portal/pages/role/components/role-page-navigation/role-page-navigations.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "RoleService", + function ($rootScope, $scope, ngAppSettings, roleServices) { + var ctrl = this; + ctrl.selected = null; + ctrl.updateOrders = function (index) { + ctrl.data.splice(index, 1); + for (var i = 0; i < ctrl.data.length; i++) { + ctrl.data[i].priority = i + 1; + } + }; + //ctrl.change = async function () { + // //var permission = ctrl.page.navPermission; + // //$rootScope.isBusy = true; + // //var resp = await roleServices.updatePermission(permission); + // //if (resp && resp.success) { + // // $rootScope.showMessage('Update successfully!', 'success'); + // // $rootScope.isBusy = false; + // // $scope.$apply(); + // //} + // //else { + // // if (resp) { $rootScope.showErrors(resp.errors); } + // // $rootScope.isBusy = false; + // // $scope.$apply(); + // //} + //}; + }, + ], + bindings: { + prefix: "=", + page: "=", + callback: "&", + }, +}); + modules.component("postFilterList", { templateUrl: "/mix-app/views/app-portal/pages/post/components/filter-list/filter-list.html", @@ -8096,47 +8128,6 @@ app.component("postSeo", { }, }); -modules.component("rolePageNav", { - templateUrl: - "/mix-app/views/app-portal/pages/role/components/role-page-navigation/role-page-navigations.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "RoleService", - function ($rootScope, $scope, ngAppSettings, roleServices) { - var ctrl = this; - ctrl.selected = null; - ctrl.updateOrders = function (index) { - ctrl.data.splice(index, 1); - for (var i = 0; i < ctrl.data.length; i++) { - ctrl.data[i].priority = i + 1; - } - }; - //ctrl.change = async function () { - // //var permission = ctrl.page.navPermission; - // //$rootScope.isBusy = true; - // //var resp = await roleServices.updatePermission(permission); - // //if (resp && resp.success) { - // // $rootScope.showMessage('Update successfully!', 'success'); - // // $rootScope.isBusy = false; - // // $scope.$apply(); - // //} - // //else { - // // if (resp) { $rootScope.showErrors(resp.errors); } - // // $rootScope.isBusy = false; - // // $scope.$apply(); - // //} - //}; - }, - ], - bindings: { - prefix: "=", - page: "=", - callback: "&", - }, -}); - app.component("serviceMain", { templateUrl: "/mix-app/views/app-portal/pages/service/components/main/view.html", @@ -8940,6 +8931,16 @@ app.component("themeImportPages", { }, }); +app.component("permissionParents", { + templateUrl: + "/mix-app/views/app-portal/pages/permission/components/parents/parents.html", + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + app.component("themeImportPosts", { templateUrl: "/mix-app/views/app-portal/pages/theme-import/components/theme-import-posts/view.html", @@ -9310,6 +9311,49 @@ modules.component("layoutPortalSidebar", { bindings: {}, }); +modules.component("actions", { + templateUrl: "/mix-app/views/app-portal/components/actions/actions.html", + bindings: { + primaryUrl: "=", + primaryTitle: "=", + primaryIcon: "=", + previewUrl: "=", + backUrl: "=", + contentUrl: "=", + onClearCache: "&?", + onSubmit: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "$location", + function ($rootScope, $scope, $location) { + var ctrl = this; + ctrl.visible = $rootScope.visible; + ctrl.back = function () { + if (ctrl.backUrl) { + $location.url(ctrl.backUrl); + } else { + window.history.back(); + } + }; + ctrl.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; + }; + ctrl.submit = function ($event) { + if (ctrl.onSubmit) { + $event.preventDefault(); + ctrl.onSubmit(); + return; + } + }; + ctrl.clearCache = function () { + ctrl.onClearCache(); + }; + }, + ], +}); + modules.component("aceEditor", { templateUrl: "/mix-app/views/app-portal/components/ace-editor/ace-editor.html", @@ -9417,49 +9461,6 @@ modules.component("aceEditor", { }, }); -modules.component("actions", { - templateUrl: "/mix-app/views/app-portal/components/actions/actions.html", - bindings: { - primaryUrl: "=", - primaryTitle: "=", - primaryIcon: "=", - previewUrl: "=", - backUrl: "=", - contentUrl: "=", - onClearCache: "&?", - onSubmit: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "$location", - function ($rootScope, $scope, $location) { - var ctrl = this; - ctrl.visible = $rootScope.visible; - ctrl.back = function () { - if (ctrl.backUrl) { - $location.url(ctrl.backUrl); - } else { - window.history.back(); - } - }; - ctrl.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; - }; - ctrl.submit = function ($event) { - if (ctrl.onSubmit) { - $event.preventDefault(); - ctrl.onSubmit(); - return; - } - }; - ctrl.clearCache = function () { - ctrl.onClearCache(); - }; - }, - ], -}); - modules.component("additionalColumn", { templateUrl: "/mix-app/views/app-portal/components/additional-column/view.html", @@ -9659,6 +9660,49 @@ modules.component("confirm", { }, }); +modules.component("funding", { + templateUrl: "/mix-app/views/app-portal/components/funding/view.html", + controller: [ + "$rootScope", + "$http", + function ($rootScope, $http) { + var ctrl = this; + ctrl.items = [ + { + title: "opencollective.com/mixcore", + href: "https://opencollective.com/mixcore", + logo: + "https://github.githubassets.com/images/modules/site/icons/funding_platforms/open_collective.svg", + }, + { + title: "funding.communitybridge.org/projects/mixcore", + href: "https://crowdfunding.lfx.linuxfoundation.org/projects/mixcore", + logo: + "https://github.githubassets.com/images/modules/site/icons/funding_platforms/community_bridge.svg", + }, + { + title: "patreon.com/mixcore", + href: "https://www.patreon.com/mixcore/creators", + logo: + "https://github.githubassets.com/images/modules/site/icons/funding_platforms/patreon.svg", + }, + { + title: "paypalme/mixcore", + href: "https://www.paypal.me/mixcore", + logo: "/mix-app/assets/img/svg/heart.svg", + }, + { + title: "buymeacoffee.com/mixcore", + href: "https://www.buymeacoffee.com/mixcore", + logo: "/mix-app/assets/img/svg/heart.svg", + }, + ]; + ctrl.init = function () {}; + }, + ], + bindings: {}, +}); + modules.component("customImage", { templateUrl: "/mix-app/views/app-portal/components/custom-image/custom-image.html", @@ -9871,74 +9915,30 @@ modules.component("filterList", { ctrl.dateRange.fromDate ).toISOString(); } else { - $scope.request.fromDate = null; - } - if (Date.parse(ctrl.dateRange.toDate)) { - ctrl.request.toDate = new Date(ctrl.dateRange.toDate).toISOString(); - } else { - ctrl.request.toDate = null; - } - $rootScope.setRequest(ctrl.request, ctrl.key); - ctrl.callback({ pageIndex: 0 }); - }; - }, - ], - bindings: { - request: "=", - key: "=?", - arrOrderby: "=?", - createUrl: "=", - createText: "=", - callback: "&", - }, -}); - -modules.component("funding", { - templateUrl: "/mix-app/views/app-portal/components/funding/view.html", - controller: [ - "$rootScope", - "$http", - function ($rootScope, $http) { - var ctrl = this; - ctrl.items = [ - { - title: "opencollective.com/mixcore", - href: "https://opencollective.com/mixcore", - logo: - "https://github.githubassets.com/images/modules/site/icons/funding_platforms/open_collective.svg", - }, - { - title: "funding.communitybridge.org/projects/mixcore", - href: "https://crowdfunding.lfx.linuxfoundation.org/projects/mixcore", - logo: - "https://github.githubassets.com/images/modules/site/icons/funding_platforms/community_bridge.svg", - }, - { - title: "patreon.com/mixcore", - href: "https://www.patreon.com/mixcore/creators", - logo: - "https://github.githubassets.com/images/modules/site/icons/funding_platforms/patreon.svg", - }, - { - title: "paypalme/mixcore", - href: "https://www.paypal.me/mixcore", - logo: "/mix-app/assets/img/svg/heart.svg", - }, - { - title: "buymeacoffee.com/mixcore", - href: "https://www.buymeacoffee.com/mixcore", - logo: "/mix-app/assets/img/svg/heart.svg", - }, - ]; - ctrl.init = function () {}; + $scope.request.fromDate = null; + } + if (Date.parse(ctrl.dateRange.toDate)) { + ctrl.request.toDate = new Date(ctrl.dateRange.toDate).toISOString(); + } else { + ctrl.request.toDate = null; + } + $rootScope.setRequest(ctrl.request, ctrl.key); + ctrl.callback({ pageIndex: 0 }); + }; }, ], - bindings: {}, + bindings: { + request: "=", + key: "=?", + arrOrderby: "=?", + createUrl: "=", + createText: "=", + callback: "&", + }, }); -modules.component("githubContributers", { - templateUrl: - "/mix-app/views/app-portal/components/github-contributers/view.html", +modules.component("githubReleases", { + templateUrl: "/mix-app/views/app-portal/components/github-releases/view.html", controller: [ "$rootScope", "$http", @@ -9948,7 +9948,7 @@ modules.component("githubContributers", { ctrl.init = function () { var req = { method: "GET", - url: "https://api.github.com/repos/mixcore/mix.core/contributors", + url: "https://api.github.com/repos/mixcore/mix.core/releases", }; ctrl.getGithubApiResult(req); }; @@ -9974,8 +9974,9 @@ modules.component("githubContributers", { bindings: {}, }); -modules.component("githubReleases", { - templateUrl: "/mix-app/views/app-portal/components/github-releases/view.html", +modules.component("githubContributers", { + templateUrl: + "/mix-app/views/app-portal/components/github-contributers/view.html", controller: [ "$rootScope", "$http", @@ -9985,7 +9986,7 @@ modules.component("githubReleases", { ctrl.init = function () { var req = { method: "GET", - url: "https://api.github.com/repos/mixcore/mix.core/releases", + url: "https://api.github.com/repos/mixcore/mix.core/contributors", }; ctrl.getGithubApiResult(req); }; @@ -10217,110 +10218,243 @@ modules.component("googleAnalytic", { ], }); -(function (angular) { - app.component("headerNav", { - templateUrl: - "/mix-app/views/app-portal/components/header-nav/headerNav.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "localStorageService", - "CommonService", - "ApiService", - "AuthService", - "CultureService", - function ( - $rootScope, - $scope, - ngAppSettings, - localStorageService, - commonService, - apiService, - authService, - cultureService - ) { - var ctrl = this; - ctrl.appSettings = $rootScope.globalSettings; - ctrl.isInRole = $rootScope.isInRole; - this.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; - ctrl.mixConfigurations = $rootScope.mixConfigurations; - cultureService.getList(ngAppSettings.request).then((resp) => { - ctrl.cultures = resp.data.items; - ctrl.selectedCulture = ctrl.cultures.find( - (m) => - m.specificulture == $rootScope.globalSettings.defaultCulture - ); - $scope.$apply(); - }); - authService.fillAuthData().then(() => { - if ( - authService.authentication && - authService.authentication.info.userData - ) { - ctrl.avatar = authService.authentication.info.userData.avatar; - } - }); - }; - ctrl.translate = $rootScope.translate; - ctrl.getConfiguration = function (keyword, isWrap, defaultText) { - return $rootScope.getConfiguration(keyword, isWrap, defaultText); - }; - ctrl.changeLang = function (culture) { - $rootScope.globalSettings.defaultCulture = culture.specificulture; - localStorageService.set("globalSettings", $rootScope.globalSettings); - window.top.location = location.href; - }; - ctrl.logOut = function () { - $rootScope.logOut(); - }; - ctrl.addPermission = function () { - $("#dlg-permission").modal("show"); - }; - ctrl.addBookmark = function () { - $("#dlg-bookmark").modal("show"); - }; - ctrl.toggleSidebar = function () { - $(".main-sidebar").toggle(); - $(".sub-sidebar").toggle(); - // $('.navbar-brand').toggle(); - }; - ctrl.clearCache = async function () { - $rootScope.isBusy = true; - await commonService.clearCache(); - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - }; - ctrl.showHelper = function (url) { - $rootScope.helperUrl = url; - $("#dev-helper-modal").modal("show"); - }; - ctrl.generateSitemap = async function () { - $rootScope.isBusy = true; - var resp = await commonService.genrateSitemap(); - if (resp) { - window.top.location.href = - "/admin/file/details?folder=" + - resp.fileFolder + - "&filename=" + - resp.fileName + - resp.extension; - } else { - $rootScope.isBusy = false; - $rootScope.showErrors(["Server error"]); - } - }; - }, - ], - bindings: { - breadCrumbs: "=", - settings: "=", - }, - }); -})(window.angular); - +(function (angular) { + app.component("headerNav", { + templateUrl: + "/mix-app/views/app-portal/components/header-nav/headerNav.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "localStorageService", + "CommonService", + "ApiService", + "AuthService", + "CultureService", + function ( + $rootScope, + $scope, + ngAppSettings, + localStorageService, + commonService, + apiService, + authService, + cultureService + ) { + var ctrl = this; + ctrl.appSettings = $rootScope.globalSettings; + ctrl.isInRole = $rootScope.isInRole; + this.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; + ctrl.mixConfigurations = $rootScope.mixConfigurations; + cultureService.getList(ngAppSettings.request).then((resp) => { + ctrl.cultures = resp.data.items; + ctrl.selectedCulture = ctrl.cultures.find( + (m) => + m.specificulture == $rootScope.globalSettings.defaultCulture + ); + $scope.$apply(); + }); + authService.fillAuthData().then(() => { + if ( + authService.authentication && + authService.authentication.info.userData + ) { + ctrl.avatar = authService.authentication.info.userData.avatar; + } + }); + }; + ctrl.translate = $rootScope.translate; + ctrl.getConfiguration = function (keyword, isWrap, defaultText) { + return $rootScope.getConfiguration(keyword, isWrap, defaultText); + }; + ctrl.changeLang = function (culture) { + $rootScope.globalSettings.defaultCulture = culture.specificulture; + localStorageService.set("globalSettings", $rootScope.globalSettings); + window.top.location = location.href; + }; + ctrl.logOut = function () { + $rootScope.logOut(); + }; + ctrl.addPermission = function () { + $("#dlg-permission").modal("show"); + }; + ctrl.addBookmark = function () { + $("#dlg-bookmark").modal("show"); + }; + ctrl.toggleSidebar = function () { + $(".main-sidebar").toggle(); + $(".sub-sidebar").toggle(); + // $('.navbar-brand').toggle(); + }; + ctrl.clearCache = async function () { + $rootScope.isBusy = true; + await commonService.clearCache(); + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + }; + ctrl.showHelper = function (url) { + $rootScope.helperUrl = url; + $("#dev-helper-modal").modal("show"); + }; + ctrl.generateSitemap = async function () { + $rootScope.isBusy = true; + var resp = await commonService.genrateSitemap(); + if (resp) { + window.top.location.href = + "/admin/file/details?folder=" + + resp.fileFolder + + "&filename=" + + resp.fileName + + resp.extension; + } else { + $rootScope.isBusy = false; + $rootScope.showErrors(["Server error"]); + } + }; + }, + ], + bindings: { + breadCrumbs: "=", + settings: "=", + }, + }); +})(window.angular); + +modules.component("hubMessages", { + templateUrl: + "/mix-app/views/app-portal/components/hub-messages/hub-messages.html", + controller: "HubMessagesController", + bindings: {}, +}); +app.controller("HubMessagesController", [ + "$scope", + "$rootScope", + "AuthService", + function ($scope, $rootScope, authService) { + BaseHub.call(this, $scope); + authService.fillAuthData(); + $scope.newMsgCount = 0; + $scope.messages = []; + $scope.onConnected = () => { + $scope.joinRoom("portal"); + }; + $scope.init = function () { + $scope.startConnection( + "portalHub", + authService.authentication.accessToken, + (err) => { + if ( + authService.authentication.refreshToken && + err.message.indexOf("401") >= 0 + ) { + authService.refreshToken().then(async () => { + $scope.startConnection( + "portalHub", + authService.authentication.accessToken + ); + }); + } + } + ); + }; + $scope.readMessages = function () { + $scope.newMsgCount = 0; + $("#modal-hub-messages").modal("show"); + }; + $scope.receiveMessage = function (msg) { + switch (msg.action) { + case "MyConnection": + $scope.hubRequest.from = msg.data; + $scope.$apply(); + break; + case "MemberList": + $scope.members = msg.data; + $scope.$apply(); + break; + case "NewMember": + $scope.newMember(msg.data); + break; + case "MemberOffline": + $scope.removeMember(msg.data); + case "NewMessage": + $scope.newMessage(msg); + break; + } + }; + $scope.newMessage = function (msg) { + msg.style = $scope.getMessageType(msg.type); + $scope.messages.push(msg); + if ( + !msg.from || + msg.from.connectionId != $scope.hubRequest.from.connectionId + ) { + $scope.newMsgCount += 1; + $rootScope.showMessage(msg.title, msg.style); + } + $scope.$apply(); + }; + $scope.removeMember = function (member) { + var index = $scope.members.findIndex( + (x) => x.username === member.username + ); + if (index >= 0) { + $scope.members.splice(index, 1); + } + $scope.$apply(); + }; + + $scope.newMember = function (member) { + var index = $scope.members.findIndex( + (x) => x.username === member.username + ); + if (index < 0) { + $scope.members.splice(0, 0, member); + } + $scope.$apply(); + }; + $scope.getMessageType = function (type) { + switch (type) { + case "Success": + return "success"; + case "Error": + return "danger"; + case "Warning": + return "warning"; + case "Info": + return "info"; + default: + return "default"; + } + }; + }, +]); + +modules.component("jumbotrons", { + templateUrl: + "/mix-app/views/app-portal/components/jumbotrons/jumbotrons.html", + controller: [ + "$rootScope", + "$scope", + "$location", + function ($rootScope, $scope, $location) { + var ctrl = this; + ctrl.translate = function (keyword) { + return $rootScope.translate(keyword); + }; + // ctrl.back = function () { + // ctrl.backUrl = ctrl.backUrl || '/admin'; + // $location.path(ctrl.backUrl); + // }; + }, + ], + bindings: { + tagName: "=", + tagType: "=", + }, +}); + modules.component("highFrequencyMessages", { templateUrl: "/mix-app/views/app-portal/components/high-frequency-messages/view.html", @@ -10498,115 +10632,6 @@ app.controller("HighFrequencyMessagesController", [ }, ]); -modules.component("hubMessages", { - templateUrl: - "/mix-app/views/app-portal/components/hub-messages/hub-messages.html", - controller: "HubMessagesController", - bindings: {}, -}); -app.controller("HubMessagesController", [ - "$scope", - "$rootScope", - "AuthService", - function ($scope, $rootScope, authService) { - BaseHub.call(this, $scope); - authService.fillAuthData(); - $scope.newMsgCount = 0; - $scope.messages = []; - $scope.onConnected = () => { - $scope.joinRoom("portal"); - }; - $scope.init = function () { - $scope.startConnection( - "portalHub", - authService.authentication.accessToken, - (err) => { - if ( - authService.authentication.refreshToken && - err.message.indexOf("401") >= 0 - ) { - authService.refreshToken().then(async () => { - $scope.startConnection( - "portalHub", - authService.authentication.accessToken - ); - }); - } - } - ); - }; - $scope.readMessages = function () { - $scope.newMsgCount = 0; - $("#modal-hub-messages").modal("show"); - }; - $scope.receiveMessage = function (msg) { - switch (msg.action) { - case "MyConnection": - $scope.hubRequest.from = msg.data; - $scope.$apply(); - break; - case "MemberList": - $scope.members = msg.data; - $scope.$apply(); - break; - case "NewMember": - $scope.newMember(msg.data); - break; - case "MemberOffline": - $scope.removeMember(msg.data); - case "NewMessage": - $scope.newMessage(msg); - break; - } - }; - $scope.newMessage = function (msg) { - msg.style = $scope.getMessageType(msg.type); - $scope.messages.push(msg); - if ( - !msg.from || - msg.from.connectionId != $scope.hubRequest.from.connectionId - ) { - $scope.newMsgCount += 1; - $rootScope.showMessage(msg.title, msg.style); - } - $scope.$apply(); - }; - $scope.removeMember = function (member) { - var index = $scope.members.findIndex( - (x) => x.username === member.username - ); - if (index >= 0) { - $scope.members.splice(index, 1); - } - $scope.$apply(); - }; - - $scope.newMember = function (member) { - var index = $scope.members.findIndex( - (x) => x.username === member.username - ); - if (index < 0) { - $scope.members.splice(0, 0, member); - } - $scope.$apply(); - }; - $scope.getMessageType = function (type) { - switch (type) { - case "Success": - return "success"; - case "Error": - return "danger"; - case "Warning": - return "warning"; - case "Info": - return "info"; - default: - return "default"; - } - }; - }, -]); - modules.component("jsonBuilder", { templateUrl: "/mix-app/views/app-portal/components/json-builder/view.html", bindings: { @@ -10867,46 +10892,22 @@ modules.component("jsonBuilder", { ctrl.parseJsonObject(); }; ctrl.clone = function (item, list) { - var obj = angular.copy(item); - obj.name = item.name + "_copy"; - item.showMenu = false; - obj.showMenu = false; - list.items.push(obj); - ctrl.parseJsonObject(); - }; - - ctrl.remove = function (index, list) { - if (confirm("Remove this")) { - list.splice(index, 1); - ctrl.parseJsonObject(); - } - }; - }, - ], -}); - -modules.component("jumbotrons", { - templateUrl: - "/mix-app/views/app-portal/components/jumbotrons/jumbotrons.html", - controller: [ - "$rootScope", - "$scope", - "$location", - function ($rootScope, $scope, $location) { - var ctrl = this; - ctrl.translate = function (keyword) { - return $rootScope.translate(keyword); + var obj = angular.copy(item); + obj.name = item.name + "_copy"; + item.showMenu = false; + obj.showMenu = false; + list.items.push(obj); + ctrl.parseJsonObject(); + }; + + ctrl.remove = function (index, list) { + if (confirm("Remove this")) { + list.splice(index, 1); + ctrl.parseJsonObject(); + } }; - // ctrl.back = function () { - // ctrl.backUrl = ctrl.backUrl || '/admin'; - // $location.path(ctrl.backUrl); - // }; }, ], - bindings: { - tagName: "=", - tagType: "=", - }, }); // const { data } = require("jquery"); @@ -11120,88 +11121,6 @@ modules.component("listMixColumn", { ], }); -modules.component("logStream", { - templateUrl: "/mix-app/views/app-portal/components/log-stream/view.html", - controller: "LogStreamController", - bindings: {}, -}); -app.controller("LogStreamController", [ - "$scope", - "$rootScope", - "AuthService", - function ($scope, $rootScope, authService) { - BaseHub.call(this, $scope); - authService.fillAuthData(); - $scope.newMsgCount = 0; - $scope.messages = []; - $scope.onConnected = () => { - $scope.joinRoom("portal"); - }; - $scope.init = function () { - $scope.startConnection( - "log-stream-hub", - authService.authentication.accessToken, - (err) => { - if ( - authService.authentication.refreshToken && - err.message.indexOf("401") >= 0 - ) { - authService.refreshToken().then(async () => { - $scope.startConnection( - "log-stream-hub", - authService.authentication.accessToken - ); - }); - } - } - ); - }; - $scope.readMessages = function () { - $scope.newMsgCount = 0; - $("#modal-log-stream").modal("show"); - }; - $scope.receiveMessage = function (msg) { - switch (msg.action) { - case "NewMessage": - $scope.newMessage(msg); - break; - } - }; - $scope.newMessage = function (msg) { - msg.style = $scope.getMessageType(msg.type); - if (msg.data) { - msg.data = JSON.parse(msg.data); - } - $scope.messages.push(msg); - $scope.$apply(); - let container = $("#modal-log-stream").find(".modal-body")[0]; - setTimeout(() => { - let h = $("#modal-log-stream").find(".table").height(); - $(container).animate( - { - scrollTop: h, // Scroll to top of body - }, - 500 - ); - }, 200); - }; - $scope.getMessageType = function (type) { - switch (type) { - case "Success": - return "success"; - case "Error": - return "danger"; - case "Warning": - return "warning"; - case "Info": - return "info"; - default: - return "default"; - } - }; - }, -]); - modules.component("mainSideBar", { templateUrl: "/mix-app/views/app-portal/components/main-side-bar/main-side-bar.html", @@ -11319,6 +11238,67 @@ modules.component("mainSideBarItemDynamic", { }, }); +modules.component("mediaUpload", { + templateUrl: + "/mix-app/views/app-portal/components/media-upload/media-upload.html", + controller: [ + "$scope", + "$rootScope", + "MediaService", + "ApiService", + "CommonService", + function ($scope, $rootScope, service, apiService, commonService) { + var ctrl = this; + ctrl.default = { + title: "", + description: "", + status: "Published", + fileFolder: "Medias", + mediaFile: { + file: null, + fullPath: "", + folderName: "Media", + fileFolder: "", + fileName: "", + extension: "", + content: "", + fileStream: "", + }, + }; + ctrl.viewmodel = angular.copy(ctrl.default); + ctrl.onInsert = function (data) { + if (ctrl.onUpdate) { + ctrl.onUpdate(); + } + }; + ctrl.save = async function (data) { + $rootScope.isBusy = true; + var resp = await service.save(data); + if (resp && resp.success) { + $scope.viewmodel = resp.data; + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + ctrl.viewmodel = angular.copy(ctrl.default); + if (ctrl.onUpdate) { + ctrl.onUpdate(); + } + $("#modal-files .modal-body").animate({ scrollTop: "0px" }, 500); + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, + ], + bindings: { + onUpdate: "&?", + }, +}); + modules.component("mediaFileUpload", { templateUrl: "/mix-app/views/app-portal/components/media-file-upload/view.html", @@ -11430,161 +11410,62 @@ modules.component("mediaFileUpload", { var response = await mediaService.uploadMedia( file, null, - ctrl.onUploadFileProgress - ); - if (response.success) { - ctrl.media = response.data; - $rootScope.isBusy = false; - ctrl.srcUrl = response.data; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - } - } else { - return null; - } - }; - ctrl.getBase64 = function (file) { - if (file !== null) { - $rootScope.isBusy = true; - var reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function () { - if (ctrl.mediaFile) { - ctrl.mediaFile.fileName = file.name.substring( - 0, - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.fileStream = reader.result; - } - ctrl.srcUrl = reader.result; - ctrl.isImage = - ctrl.srcUrl.indexOf("data:image/") >= 0 || - ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); - ctrl.src = reader.result; - $rootScope.isBusy = false; - $scope.$apply(); - }; - reader.onerror = function (error) { - $rootScope.isBusy = false; - $rootScope.showErrors([error]); - }; - } else { - return null; - } - }; - ctrl.onUploadFileProgress = function (progress) { - ctrl.progress = progress; - }; - }, - ], -}); - -modules.component("mediaUpload", { - templateUrl: - "/mix-app/views/app-portal/components/media-upload/media-upload.html", - controller: [ - "$scope", - "$rootScope", - "MediaService", - "ApiService", - "CommonService", - function ($scope, $rootScope, service, apiService, commonService) { - var ctrl = this; - ctrl.default = { - title: "", - description: "", - status: "Published", - fileFolder: "Medias", - mediaFile: { - file: null, - fullPath: "", - folderName: "Media", - fileFolder: "", - fileName: "", - extension: "", - content: "", - fileStream: "", - }, - }; - ctrl.viewmodel = angular.copy(ctrl.default); - ctrl.onInsert = function (data) { - if (ctrl.onUpdate) { - ctrl.onUpdate(); - } - }; - ctrl.save = async function (data) { - $rootScope.isBusy = true; - var resp = await service.save(data); - if (resp && resp.success) { - $scope.viewmodel = resp.data; - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - ctrl.viewmodel = angular.copy(ctrl.default); - if (ctrl.onUpdate) { - ctrl.onUpdate(); + ctrl.onUploadFileProgress + ); + if (response.success) { + ctrl.media = response.data; + $rootScope.isBusy = false; + ctrl.srcUrl = response.data; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } } - $("#modal-files .modal-body").animate({ scrollTop: "0px" }, 500); - $scope.$apply(); } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); + return null; } }; - }, - ], - bindings: { - onUpdate: "&?", - }, -}); - -modules.component("mediumNews", { - templateUrl: "/mix-app/views/app-portal/components/medium-news/view.html", - controller: [ - "$rootScope", - "$http", - function ($rootScope, $http) { - var ctrl = this; - ctrl.items = []; - ctrl.init = function () { - var req = { - method: "GET", - url: - "https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/mixcore&api_key=qww481wpgat3g4iqvqss7spzrilkbekpxpjgrbof&t=" + - Math.floor(Date.now() / 1000), - }; - ctrl.getMediumApiResult(req); - }; - - ctrl.getMediumApiResult = async function (req) { - return $http(req).then( - function (resp) { - if (resp.status == "200") { - ctrl.items = resp.data.items; + ctrl.getBase64 = function (file) { + if (file !== null) { + $rootScope.isBusy = true; + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + if (ctrl.mediaFile) { + ctrl.mediaFile.fileName = file.name.substring( + 0, + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.fileStream = reader.result; } - }, - function (error) { - return { - success: false, - errors: [error.statusText || error.status], - }; - } - ); + ctrl.srcUrl = reader.result; + ctrl.isImage = + ctrl.srcUrl.indexOf("data:image/") >= 0 || + ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); + ctrl.src = reader.result; + $rootScope.isBusy = false; + $scope.$apply(); + }; + reader.onerror = function (error) { + $rootScope.isBusy = false; + $rootScope.showErrors([error]); + }; + } else { + return null; + } + }; + ctrl.onUploadFileProgress = function (progress) { + ctrl.progress = progress; }; }, ], - bindings: {}, }); app.component("mixMetadata", { @@ -11780,6 +11661,44 @@ app.component("mixMetadata", { ], }); +modules.component("mediumNews", { + templateUrl: "/mix-app/views/app-portal/components/medium-news/view.html", + controller: [ + "$rootScope", + "$http", + function ($rootScope, $http) { + var ctrl = this; + ctrl.items = []; + ctrl.init = function () { + var req = { + method: "GET", + url: + "https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/mixcore&api_key=qww481wpgat3g4iqvqss7spzrilkbekpxpjgrbof&t=" + + Math.floor(Date.now() / 1000), + }; + ctrl.getMediumApiResult(req); + }; + + ctrl.getMediumApiResult = async function (req) { + return $http(req).then( + function (resp) { + if (resp.status == "200") { + ctrl.items = resp.data.items; + } + }, + function (error) { + return { + success: false, + errors: [error.statusText || error.status], + }; + } + ); + }; + }, + ], + bindings: {}, +}); + modules.component("mixDatabaseColumn", { templateUrl: "/mix-app/views/app-portal/components/mix-database-column/view.html", @@ -11890,130 +11809,6 @@ modules.component("mixDatabaseColumn", { ], }); -modules.component("mixDatabaseDataFilter", { - templateUrl: - "/mix-app/views/app-portal/components/mix-database-data-filter/view.html", - bindings: { - query: "=", - mixDatabaseName: "=?", - mixDatabaseId: "=?", - selectedList: "=", - initData: "=?", - columns: "=?", - selected: "=", - callback: "&?", - save: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "RestMixDatabaseDataPortalService", - function ($rootScope, $scope, ngAppSettings, dataService) { - var ctrl = this; - ctrl.request = angular.copy(ngAppSettings.request); - ctrl.types = ["Page", "Post"]; - ctrl.type = "Page"; - ctrl.navs = []; - ctrl.data = { items: [] }; - ctrl.goToPath = $rootScope.goToPath; - ctrl.$onInit = function () { - if (ctrl.initData) { - ctrl.data = ctrl.initData; - } else { - ctrl.loadData(); - } - }; - ctrl.loadData = async function (pageIndex) { - ctrl.isBusy = true; - - // ctrl.request.query = ctrl.query + ctrl.srcId; - ctrl.navs = []; - if (pageIndex !== undefined) { - ctrl.request.pageIndex = pageIndex; - } - if (ctrl.request.fromDate !== null) { - var df = new Date(ctrl.request.fromDate); - ctrl.request.fromDate = df.toISOString(); - } - if (ctrl.request.toDate !== null) { - var dt = new Date(ctrl.request.toDate); - ctrl.request.toDate = dt.toISOString(); - } - if (ctrl.mixDatabaseId) { - ctrl.request.mixDatabaseId = ctrl.mixDatabaseId; - } - if (ctrl.mixDatabaseName) { - ctrl.request.mixDatabaseName = ctrl.mixDatabaseName; - } - if (ctrl.filterType) { - ctrl.request.filterType = ctrl.filterType; - } - - var response = await dataService.getList(ctrl.request); - if (response.success) { - ctrl.data = response.data; - ctrl.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - ctrl.isBusy = false; - $scope.$apply(); - } - }; - ctrl.edit = function (nav) { - switch (ctrl.type) { - case "Page": - ctrl.goToPath(`/admin/page/details/${nav.id}`); - break; - case "Post": - ctrl.goToPath(`/admin/post/details/${nav.id}`); - break; - case "Module": - ctrl.goToPath(`/admin/module/details/${nav.id}`); - break; - } - }; - ctrl.onClose = function () { - ctrl.callback(); - }; - ctrl.select = function (nav) { - var current = $rootScope.findObjectByKey(ctrl.data.items, "id", nav.id); - if (!nav.isActive && ctrl.callback) { - ctrl.callback({ nav: nav }); - } - if (ctrl.isMultiple) { - current.isActive = !current.isActive; - } else { - if (!nav.isActive) { - angular.forEach(ctrl.data.items, (element) => { - element.isActive = false; - }); - } - current.isActive = !nav.isActive; - } - }; - ctrl.saveSelected = function () { - ctrl.selected = $rootScope.filterArray( - ctrl.data, - ["isActived"], - [true] - ); - setTimeout(() => { - ctrl.save().then(() => { - ctrl.loadPosts(); - }); - }, 500); - }; - ctrl.limString = function (str, max) { - if (str) { - return str.length > max ? str.substring(0, max) + " ..." : str; - } - }; - }, - ], -}); - modules.component("mixDatabaseDataValueEditor", { templateUrl: "/mix-app/views/app-portal/components/mix-database-data-value-editor/view.html", @@ -12231,229 +12026,125 @@ modules.component("mixDatabaseDataValueEditor", { ], }); -modules.component("mixDatabaseDataValues", { +modules.component("mixDatabaseDataFilter", { templateUrl: - "/mix-app/views/app-portal/components/mix-database-data-values/view.html", + "/mix-app/views/app-portal/components/mix-database-data-filter/view.html", bindings: { - database: "=?", + query: "=", mixDatabaseName: "=?", - mixDatabaseTitle: "=?", mixDatabaseId: "=?", - parentName: "=?", - parentId: "=?", - header: "=?", - data: "=?", - canDrag: "=?", - queries: "=?", - filterType: "=?", - compareType: "=?", - selectedList: "=?", - selectSingle: "=?", - database: "=?", - onFilterList: "&?", - onApplyList: "&?", - onSendMail: "&?", - onUpdate: "&?", - onDuplicate: "&?", - onDelete: "&?", + selectedList: "=", + initData: "=?", + columns: "=?", + selected: "=", + callback: "&?", + save: "&?", }, controller: [ "$rootScope", "$scope", - "$location", - "$routeParams", "ngAppSettings", - "RestMixDatabasePortalService", - "MixDbService", - function ( - $rootScope, - $scope, - $location, - $routeParams, - ngAppSettings, - databaseService, - dataService - ) { + "RestMixDatabaseDataPortalService", + function ($rootScope, $scope, ngAppSettings, dataService) { var ctrl = this; - ctrl.intShowColumn = 3; ctrl.request = angular.copy(ngAppSettings.request); - ctrl.actions = ["Delete", "SendMail"]; - ctrl.filterTypes = ["contain", "equal"]; - ctrl.compareTypes = ["or", "and"]; - ctrl.selectedProp = null; - ctrl.mixConfigurations = $rootScope.globalSettings; - ctrl.$onInit = async function () { - dataService.initDbName(ctrl.mixDatabaseName); - ctrl.request.name = ctrl.mixDatabaseName; - ctrl.request.parentName = ctrl.parentName; - ctrl.request.parentId = ctrl.parentId; - if (!ctrl.selectedList) { - ctrl.selectedList = { - action: "Delete", - data: [], - }; + ctrl.types = ["Page", "Post"]; + ctrl.type = "Page"; + ctrl.navs = []; + ctrl.data = { items: [] }; + ctrl.goToPath = $rootScope.goToPath; + ctrl.$onInit = function () { + if (ctrl.initData) { + ctrl.data = ctrl.initData; + } else { + ctrl.loadData(); } - if (!ctrl.database) { - var getDatabase = await databaseService.getByName( - ctrl.mixDatabaseName - ); - if (getDatabase.success) { - ctrl.database = getDatabase.data; - $scope.$apply(); - } + }; + ctrl.loadData = async function (pageIndex) { + ctrl.isBusy = true; + + // ctrl.request.query = ctrl.query + ctrl.srcId; + ctrl.navs = []; + if (pageIndex !== undefined) { + ctrl.request.pageIndex = pageIndex; } - if (!ctrl.data) { - await ctrl.loadData(); + if (ctrl.request.fromDate !== null) { + var df = new Date(ctrl.request.fromDate); + ctrl.request.fromDate = df.toISOString(); } - ctrl.createUrl = `/admin/mix-database-data/create?mixDatabaseId=${ - ctrl.database.id - }&mixDatabaseName=${ctrl.database.systemName}&mixDatabaseTitle=${ - ctrl.database.displayName - }&dataContentId=default&parentId=${ctrl.parentId || ""}&parentName=${ - ctrl.parentName || "" - }`; - $scope.$apply(); - }; - ctrl.loadData = async function () { - dataService.initDbName(ctrl.mixDatabaseName); - ctrl.request.queries = []; - if (ctrl.queries) { - Object.keys(ctrl.queries).forEach((e) => { - if (ctrl.queries[e]) { - ctrl.request.queries.push({ - fieldName: e, - value: ctrl.queries[e], - }); - } - }); + if (ctrl.request.toDate !== null) { + var dt = new Date(ctrl.request.toDate); + ctrl.request.toDate = dt.toISOString(); } - var getData = await dataService.filter(ctrl.request); - ctrl.data = getData.data; - ctrl.selectedIds = ctrl.data.items.map((m) => m.id); - $scope.$apply(); - }; - ctrl.select = function (item) { - if (item.isSelected) { - if (ctrl.selectSingle == "true") { - ctrl.selectedList.data.items = []; - ctrl.selectedList.data.items.push(item); - } else { - var current = $rootScope.findObjectByKey( - ctrl.selectedList, - "id", - item.id - ); - if (!current) { - ctrl.selectedList.data.items.push(item); - } - } - } else { - $rootScope.removeObject(ctrl.selectedList, item.id); + if (ctrl.mixDatabaseId) { + ctrl.request.mixDatabaseId = ctrl.mixDatabaseId; + } + if (ctrl.mixDatabaseName) { + ctrl.request.mixDatabaseName = ctrl.mixDatabaseName; + } + if (ctrl.filterType) { + ctrl.request.filterType = ctrl.filterType; } - }; - ctrl.selectAll = function (isSelected) { - ctrl.selectedList.data.items = []; - angular.forEach(ctrl.data.items, function (e) { - e.isSelected = isSelected; - if (isSelected) { - ctrl.selectedList.data.items.push(e.id); - } - }); - }; - ctrl.filter = function () { - ctrl.data.items = []; - ctrl.loadData(); - }; - ctrl.sendMail = async function (data) { - ctrl.onSendMail({ data: data }); - }; - ctrl.apply = async function () { - ctrl.onApplyList(); - }; - - ctrl.duplicate = function (data) { - ctrl.onDuplicate({ data: data }); - }; - - ctrl.update = function (data) { - let url = `/admin/mix-database-data/details?dataContentId=${ - data.id - }&mixDatabaseName=${ctrl.mixDatabaseName}&mixDatabaseTitle=${ - ctrl.mixDatabaseTitle - }&parentId=${ctrl.parentId || ""}&parentName=${ctrl.parentName || ""}`; - $location.url(url); - }; - - ctrl.delete = function (data) { - $rootScope.showConfirm( - ctrl, - "removeConfirmed", - [data.id], - null, - "Remove", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - ctrl.removeConfirmed = async function (dataContentId) { - $rootScope.isBusy = true; - var result = await dataService.delete([dataContentId]); - if (result.success) { - if (ctrl.onDelete) { - ctrl.onDelete({ data: dataContentId }); - } - await ctrl.loadData(); - $rootScope.isBusy = false; + var response = await dataService.getList(ctrl.request); + if (response.success) { + ctrl.data = response.data; + ctrl.isBusy = false; $scope.$apply(); } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; + $rootScope.showErrors(response.errors); + ctrl.isBusy = false; $scope.$apply(); } }; - - ctrl.filterData = function (item, attributeName) { - return $rootScope.findObjectByKey( - item.data.items, - "attributeName", - attributeName - ); + ctrl.edit = function (nav) { + switch (ctrl.type) { + case "Page": + ctrl.goToPath(`/admin/page/details/${nav.id}`); + break; + case "Post": + ctrl.goToPath(`/admin/post/details/${nav.id}`); + break; + case "Module": + ctrl.goToPath(`/admin/module/details/${nav.id}`); + break; + } }; - - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - ctrl.minPriority = ctrl.data.items[0].priority; + ctrl.onClose = function () { + ctrl.callback(); }; - ctrl.updateOrders = function (index, items) { - if (index > ctrl.dragStartIndex) { - ctrl.data.items.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.data.items.splice(ctrl.dragStartIndex + 1, 1); + ctrl.select = function (nav) { + var current = $rootScope.findObjectByKey(ctrl.data.items, "id", nav.id); + if (!nav.isActive && ctrl.callback) { + ctrl.callback({ nav: nav }); } - ctrl.updateDataInfos(); - }; - ctrl.updateDataInfos = async function () { - angular.forEach(ctrl.data.items, async function (e, i) { - e.priority = ctrl.minPriority + i; - var resp = await dataService.saveFields(e.id, { - priority: e.priority, - }); - if (resp && resp.success) { - $scope.activedPage = resp.data; - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } + if (ctrl.isMultiple) { + current.isActive = !current.isActive; + } else { + if (!nav.isActive) { + angular.forEach(ctrl.data.items, (element) => { + element.isActive = false; + }); } - }); + current.isActive = !nav.isActive; + } }; - - ctrl.view = function (item) { - var obj = { - columns: ctrl.database.columns, - item: item, - }; - $rootScope.preview("mix-database-data", obj, null, "modal-lg"); + ctrl.saveSelected = function () { + ctrl.selected = $rootScope.filterArray( + ctrl.data, + ["isActived"], + [true] + ); + setTimeout(() => { + ctrl.save().then(() => { + ctrl.loadPosts(); + }); + }, 500); + }; + ctrl.limString = function (str, max) { + if (str) { + return str.length > max ? str.substring(0, max) + " ..." : str; + } }; }, ], @@ -12674,26 +12365,254 @@ modules.component("mixDatabaseForm", { ctrl.mixDataContent.data.uri = data.detailUrl; } }; - ctrl.filterData = function (attributeName) { - if (ctrl.mixDataContent) { - var attr = $rootScope.findObjectByKey( - ctrl.mixDataContent.data, - "mixDatabaseColumnName", - attributeName - ); - if (!attr) { - attr = angular.copy( - $rootScope.findObjectByKey( - ctrl.defaultData.data, - "mixDatabaseColumnName", - attributeName - ) - ); - mixDatabaseColumn; - ctrl.mixDataContent.data.push(attr); + ctrl.filterData = function (attributeName) { + if (ctrl.mixDataContent) { + var attr = $rootScope.findObjectByKey( + ctrl.mixDataContent.data, + "mixDatabaseColumnName", + attributeName + ); + if (!attr) { + attr = angular.copy( + $rootScope.findObjectByKey( + ctrl.defaultData.data, + "mixDatabaseColumnName", + attributeName + ) + ); + mixDatabaseColumn; + ctrl.mixDataContent.data.push(attr); + } + return attr; + } + }; + }, + ], +}); + +modules.component("mixDatabaseDataValues", { + templateUrl: + "/mix-app/views/app-portal/components/mix-database-data-values/view.html", + bindings: { + database: "=?", + mixDatabaseName: "=?", + mixDatabaseTitle: "=?", + mixDatabaseId: "=?", + parentName: "=?", + parentId: "=?", + header: "=?", + data: "=?", + canDrag: "=?", + queries: "=?", + filterType: "=?", + compareType: "=?", + selectedList: "=?", + selectSingle: "=?", + database: "=?", + onFilterList: "&?", + onApplyList: "&?", + onSendMail: "&?", + onUpdate: "&?", + onDuplicate: "&?", + onDelete: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "$location", + "$routeParams", + "ngAppSettings", + "RestMixDatabasePortalService", + "MixDbService", + function ( + $rootScope, + $scope, + $location, + $routeParams, + ngAppSettings, + databaseService, + dataService + ) { + var ctrl = this; + ctrl.intShowColumn = 3; + ctrl.request = angular.copy(ngAppSettings.request); + ctrl.actions = ["Delete", "SendMail"]; + ctrl.filterTypes = ["contain", "equal"]; + ctrl.compareTypes = ["or", "and"]; + ctrl.selectedProp = null; + ctrl.mixConfigurations = $rootScope.globalSettings; + ctrl.$onInit = async function () { + dataService.initDbName(ctrl.mixDatabaseName); + ctrl.request.name = ctrl.mixDatabaseName; + ctrl.request.parentName = ctrl.parentName; + ctrl.request.parentId = ctrl.parentId; + if (!ctrl.selectedList) { + ctrl.selectedList = { + action: "Delete", + data: [], + }; + } + if (!ctrl.database) { + var getDatabase = await databaseService.getByName( + ctrl.mixDatabaseName + ); + if (getDatabase.success) { + ctrl.database = getDatabase.data; + $scope.$apply(); + } + } + if (!ctrl.data) { + await ctrl.loadData(); + } + ctrl.createUrl = `/admin/mix-database-data/create?mixDatabaseId=${ + ctrl.database.id + }&mixDatabaseName=${ctrl.database.systemName}&mixDatabaseTitle=${ + ctrl.database.displayName + }&dataContentId=default&parentId=${ctrl.parentId || ""}&parentName=${ + ctrl.parentName || "" + }`; + $scope.$apply(); + }; + ctrl.loadData = async function () { + dataService.initDbName(ctrl.mixDatabaseName); + ctrl.request.queries = []; + if (ctrl.queries) { + Object.keys(ctrl.queries).forEach((e) => { + if (ctrl.queries[e]) { + ctrl.request.queries.push({ + fieldName: e, + value: ctrl.queries[e], + }); + } + }); + } + var getData = await dataService.filter(ctrl.request); + ctrl.data = getData.data; + ctrl.selectedIds = ctrl.data.items.map((m) => m.id); + $scope.$apply(); + }; + ctrl.select = function (item) { + if (item.isSelected) { + if (ctrl.selectSingle == "true") { + ctrl.selectedList.data.items = []; + ctrl.selectedList.data.items.push(item); + } else { + var current = $rootScope.findObjectByKey( + ctrl.selectedList, + "id", + item.id + ); + if (!current) { + ctrl.selectedList.data.items.push(item); + } + } + } else { + $rootScope.removeObject(ctrl.selectedList, item.id); + } + }; + ctrl.selectAll = function (isSelected) { + ctrl.selectedList.data.items = []; + angular.forEach(ctrl.data.items, function (e) { + e.isSelected = isSelected; + if (isSelected) { + ctrl.selectedList.data.items.push(e.id); + } + }); + }; + ctrl.filter = function () { + ctrl.data.items = []; + ctrl.loadData(); + }; + ctrl.sendMail = async function (data) { + ctrl.onSendMail({ data: data }); + }; + ctrl.apply = async function () { + ctrl.onApplyList(); + }; + + ctrl.duplicate = function (data) { + ctrl.onDuplicate({ data: data }); + }; + + ctrl.update = function (data) { + let url = `/admin/mix-database-data/details?dataContentId=${ + data.id + }&mixDatabaseName=${ctrl.mixDatabaseName}&mixDatabaseTitle=${ + ctrl.mixDatabaseTitle + }&parentId=${ctrl.parentId || ""}&parentName=${ctrl.parentName || ""}`; + $location.url(url); + }; + + ctrl.delete = function (data) { + $rootScope.showConfirm( + ctrl, + "removeConfirmed", + [data.id], + null, + "Remove", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + ctrl.removeConfirmed = async function (dataContentId) { + $rootScope.isBusy = true; + var result = await dataService.delete([dataContentId]); + if (result.success) { + if (ctrl.onDelete) { + ctrl.onDelete({ data: dataContentId }); + } + await ctrl.loadData(); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(result.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + ctrl.filterData = function (item, attributeName) { + return $rootScope.findObjectByKey( + item.data.items, + "attributeName", + attributeName + ); + }; + + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; + ctrl.minPriority = ctrl.data.items[0].priority; + }; + ctrl.updateOrders = function (index, items) { + if (index > ctrl.dragStartIndex) { + ctrl.data.items.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.data.items.splice(ctrl.dragStartIndex + 1, 1); + } + ctrl.updateDataInfos(); + }; + ctrl.updateDataInfos = async function () { + angular.forEach(ctrl.data.items, async function (e, i) { + e.priority = ctrl.minPriority + i; + var resp = await dataService.saveFields(e.id, { + priority: e.priority, + }); + if (resp && resp.success) { + $scope.activedPage = resp.data; + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } } - return attr; - } + }); + }; + + ctrl.view = function (item) { + var obj = { + columns: ctrl.database.columns, + item: item, + }; + $rootScope.preview("mix-database-data", obj, null, "modal-lg"); }; }, ], @@ -12780,227 +12699,13 @@ modules.component("mixDatabaseNavData", { $rootScope.isBusy = false; $scope.$apply(); } else { - $rootScope.showMessage(resp.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }); - } else { - $rootScope.showErrors(resp.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }); - }; - ctrl.removeData = async function (nav) { - $rootScope.showConfirm( - ctrl, - "removeDataConfirmed", - [nav], - null, - "Remove", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - ctrl.removeDataConfirmed = async function (nav) { - $rootScope.isBusy = true; - var result = await navService.delete([nav.id]); - if (result.success) { - $rootScope.removeObjectByKey(ctrl.data, "id", nav.id); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - ctrl.minPriority = ctrl.data[0].priority; - }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.data.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.data.splice(ctrl.dragStartIndex + 1, 1); - } - var arrNavs = []; - angular.forEach(ctrl.data, function (e, i) { - e.priority = ctrl.minPriority + i; - var keys = { - parentId: e.parentId, - parentType: e.parentType, - id: e.id, - }; - var properties = { - priority: e.priority, - }; - arrNavs.push({ - keys: keys, - properties: properties, - }); - }); - navService.saveProperties("portal", arrNavs).then((resp) => { - $rootScope.isBusy = false; - $scope.$apply(); - }); - }; - }, - ], -}); - -modules.component("mixDatabaseNavValues", { - templateUrl: - "/mix-app/views/app-portal/components/mix-database-nav-values/view.html", - bindings: { - mixDatabaseId: "=", - mixDatabaseName: "=", - guidParentId: "=", - parentType: "=", - columns: "=?", - header: "=", - data: "=?", - maxCol: "=?", - createUrl: "=?", - updateUrl: "=?", - onUpdate: "&?", - onDelete: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "RestRelatedAttributeDataPortalService", - "RestMixDatabaseColumnPortalService", - function ($rootScope, $scope, ngAppSettings, navService, columnService) { - var ctrl = this; - ctrl.selectedProp = null; - ctrl.request = angular.copy(ngAppSettings.restRequest); - ctrl.request.orderBy = "Priority"; - ctrl.request.query = "{}"; - - ctrl.request.direction = 0; - ctrl.mixConfigurations = $rootScope.globalSettings; - ctrl.$onInit = async function () { - ctrl.maxCol = ctrl.maxCol || 3; - if (!ctrl.createUrl) { - ctrl.createUrl = "/admin/mix-database-data/create"; - } - if (!ctrl.updateUrl) { - ctrl.updateUrl = "/admin/mix-database-data/details"; - } - if (!ctrl.columns) { - var getFields = await columnService.initData( - ctrl.mixDatabaseName || ctrl.mixDatabaseId - ); - if (getFields.success) { - ctrl.columns = getFields.data; - $scope.$apply(); - } - } - if (!ctrl.data) { - ctrl.loadData(); - } - }; - - ctrl.update = function (data) { - ctrl.onUpdate({ data: data }); - }; - - ctrl.delete = function (data) { - ctrl.onDelete({ data: data }); - }; - - ctrl.filterData = function (item, attributeName) { - return $rootScope.findObjectByKey( - item.data, - "attributeName", - attributeName - ); - }; - - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - ctrl.minPriority = ctrl.data.items[0].priority; - }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.data.items.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.data.items.splice(ctrl.dragStartIndex + 1, 1); - } - angular.forEach(ctrl.data.items, function (e, i) { - e.priority = ctrl.minPriority + i; - navService.saveFields(e.id, { priority: e.priority }).then((resp) => { - $rootScope.isBusy = false; - $scope.$apply(); - }); - }); - }; - - ctrl.loadData = function () { - ctrl.request.mixDatabaseId = ctrl.mixDatabaseId || 0; - ctrl.request.mixDatabaseName = ctrl.mixDatabaseName || null; - ctrl.request.guidParentId = ctrl.guidParentId; - ctrl.request.intParentId = ctrl.intParentId; - ctrl.request.parentType = ctrl.parentType; - navService.getList(ctrl.request).then((resp) => { - if (resp) { - ctrl.data = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors("Failed"); - } - ctrl.refData = []; - $rootScope.isBusy = false; - $scope.$apply(); - } - }); - }; - ctrl.updateData = function (nav) { - $rootScope.goToPath( - `${ctrl.updateUrl}?dataContentId=${nav.childDataContent.id}&mixDatabaseId=${nav.mixDatabaseId}&guidParentId=${ctrl.guidParentId}&parentType=${ctrl.parentType}` - ); - // ctrl.refDataModel = nav; - // var e = $(".pane-form-" + ctrl.mixDatabaseDataValue.column.referenceId)[0]; - // angular.element(e).triggerHandler('click'); - // $location.url('/admin/mix-database-data/details?dataContentId='+ item.id +'&mixDatabaseId=' + item.mixDatabaseId+'&parentType=' + item.parentType+'&parentId=' + item.parentId); - }; - ctrl.saveData = function (data) { - $rootScope.isBusy = true; - ctrl.refDataModel.data = data; - dataService.save("portal", data).then((resp) => { - if (resp.success) { - ctrl.refDataModel.id = resp.data.id; - ctrl.refDataModel.data = resp.data; - navService.save("portal", ctrl.refDataModel).then((resp) => { - if (resp.success) { - var tmp = $rootScope.findObjectByKey( - ctrl.refData, - ["parentId", "parentType", "id"], - [resp.data.parentId, resp.data.parentType, resp.data.id] - ); - if (!tmp) { - ctrl.refData.push(resp.data); - } - ctrl.refDataModel = angular.copy(ctrl.defaultDataModel); - var e = $( - ".pane-data-" + ctrl.mixDatabaseDataValue.column.referenceId - )[0]; - angular.element(e).triggerHandler("click"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); + $rootScope.showMessage(resp.errors); $rootScope.isBusy = false; $scope.$apply(); } }); } else { - $rootScope.showMessage("failed"); + $rootScope.showErrors(resp.errors); $rootScope.isBusy = false; $scope.$apply(); } @@ -13020,21 +12725,45 @@ modules.component("mixDatabaseNavValues", { $rootScope.isBusy = true; var result = await navService.delete([nav.id]); if (result.success) { - $rootScope.removeObjectByKey(ctrl.data.items, "id", nav.id); + $rootScope.removeObjectByKey(ctrl.data, "id", nav.id); $rootScope.isBusy = false; $scope.$apply(); } else { - $rootScope.showMessage("failed"); + $rootScope.showErrors(result.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - ctrl.view = function (item) { - var obj = { - columns: ctrl.columns, - item: item, - }; - $rootScope.preview("mix-database-data", obj, null, "modal-lg"); + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; + ctrl.minPriority = ctrl.data[0].priority; + }; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.data.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.data.splice(ctrl.dragStartIndex + 1, 1); + } + var arrNavs = []; + angular.forEach(ctrl.data, function (e, i) { + e.priority = ctrl.minPriority + i; + var keys = { + parentId: e.parentId, + parentType: e.parentType, + id: e.id, + }; + var properties = { + priority: e.priority, + }; + arrNavs.push({ + keys: keys, + properties: properties, + }); + }); + navService.saveProperties("portal", arrNavs).then((resp) => { + $rootScope.isBusy = false; + $scope.$apply(); + }); }; }, ], @@ -13121,395 +12850,585 @@ modules.component("mixDatabaseNavs", { $rootScope.showErrors("Others Failed"); } } - $scope.$apply(); - }; - ctrl.change = async function (nav) { - $rootScope.isBusy = true; - var result; - if (nav.isActived) { - ctrl.active(nav); - } else { - ctrl.deactive(nav); - } + $scope.$apply(); + }; + ctrl.change = async function (nav) { + $rootScope.isBusy = true; + var result; + if (nav.isActived) { + ctrl.active(nav); + } else { + ctrl.deactive(nav); + } + }; + + ctrl.deactive = async function (nav) { + let result = null; + if (nav.id) { + result = await navService.delete([nav.id]); + $(".pane-container-" + nav.data.id) + .parent() + .remove(); + } + if (result && result.success) { + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + } + }; + + ctrl.active = async function (nav) { + $rootScope.isBusy = true; + var result; + result = await navService.save(nav); + if (result && result.success) { + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + ctrl.update = function (data) { + ctrl.onUpdate({ + data: data, + }); + }; + + ctrl.delete = function (data) { + ctrl.onDelete({ + data: data, + }); + }; + + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; + ctrl.minPriority = ctrl.mixDatabaseNavs[0].priority; + }; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex + 1, 1); + } + var arrNavs = []; + angular.forEach(ctrl.mixDatabaseNavs, function (e, i) { + e.priority = ctrl.minPriority + i; + var keys = { + parentId: e.parentId, + parentType: e.parentType, + id: e.id, + }; + var properties = { + priority: e.priority, + }; + arrNavs.push({ + keys: keys, + properties: properties, + }); + }); + navService.saveProperties("portal", arrNavs).then((resp) => { + $rootScope.isBusy = false; + $scope.$apply(); + }); + }; + }, + ], +}); + +modules.component("mixFileUpload", { + templateUrl: "/mix-app/views/app-portal/components/mix-file-upload/view.html", + bindings: { + folder: "=?", + accept: "=?", + onFail: "&?", + onSuccess: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "FileServices", + function ($rootScope, $scope, ngAppSettings, fileService) { + var ctrl = this; + ctrl.mediaFile = {}; + ctrl.isAdmin = $rootScope.isAdmin; + ctrl.mediaNavs = []; + ctrl.$onInit = function () { + ctrl.id = Math.floor(Math.random() * 100); + }; + ctrl.selectFile = function (files) { + if (files !== undefined && files !== null && files.length > 0) { + const file = files[0]; + ctrl.file = file; + ctrl.mediaFile.folder = ctrl.folder ? ctrl.folder : "Media"; + ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; + ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; + ctrl.mediaFile.file = file; + if (ctrl.auto == "true") { + ctrl.uploadFile(file); + } else { + ctrl.getBase64(file); + } + } + }; + + ctrl.getBase64 = function (file) { + if (file !== null) { + $rootScope.isBusy = true; + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + if (ctrl.mediaFile) { + ctrl.mediaFile.fileName = file.name.substring( + 0, + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.fileStream = reader.result; + } + $rootScope.isBusy = false; + $scope.$apply(); + }; + reader.onerror = function (error) { + $rootScope.isBusy = false; + $rootScope.showErrors([error]); + }; + } else { + return null; + } + }; + + ctrl.uploadFile = async function () { + if (ctrl.file) { + $rootScope.isBusy = true; + var response = await fileService.uploadFile(ctrl.file, ctrl.folder); + if (response) { + if (ctrl.onSuccess) { + ctrl.onSuccess(); + } + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(['Cannot upload file']); + $rootScope.isBusy = false; + $scope.$apply(); + } + } else { + $rootScope.showErrors(["Please choose file"]); + } + }; + }, + ], +}); + +modules.component("mixFileExtract", { + templateUrl: + "/mix-app/views/app-portal/components/mix-file-extract/view.html", + bindings: { + folder: "=?", + accept: "=?", + onFail: "&?", + onSuccess: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "FileServices", + function ($rootScope, $scope, ngAppSettings, fileService) { + var ctrl = this; + ctrl.mediaFile = {}; + ctrl.isAdmin = $rootScope.isAdmin; + ctrl.mediaNavs = []; + ctrl.$onInit = function () { + ctrl.id = Math.floor(Math.random() * 100); + }; + ctrl.selectFile = function (files) { + if (files !== undefined && files !== null && files.length > 0) { + const file = files[0]; + ctrl.file = file; + ctrl.mediaFile.folder = ctrl.folder ? ctrl.folder : "Media"; + ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; + ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; + ctrl.mediaFile.file = file; + if (ctrl.auto == "true") { + ctrl.uploadFile(file); + } else { + ctrl.getBase64(file); + } + } }; - ctrl.deactive = async function (nav) { - let result = null; - if (nav.id) { - result = await navService.delete([nav.id]); - $(".pane-container-" + nav.data.id) - .parent() - .remove(); - } - if (result && result.success) { - $rootScope.isBusy = false; - $scope.$apply(); + ctrl.getBase64 = function (file) { + if (file !== null) { + $rootScope.isBusy = true; + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + if (ctrl.mediaFile) { + ctrl.mediaFile.fileName = file.name.substring( + 0, + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.fileStream = reader.result; + } + $rootScope.isBusy = false; + $scope.$apply(); + }; + reader.onerror = function (error) { + $rootScope.isBusy = false; + $rootScope.showErrors([error]); + }; } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; + return null; } }; - ctrl.active = async function (nav) { - $rootScope.isBusy = true; - var result; - result = await navService.save(nav); - if (result && result.success) { - $rootScope.isBusy = false; - $scope.$apply(); + ctrl.uploadFile = async function () { + if (ctrl.file) { + $rootScope.isBusy = true; + var response = await fileService.extractFile(ctrl.file, ctrl.folder); + if (response) { + if (ctrl.onSuccess) { + ctrl.onSuccess(); + } + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(["Cannot upload file"]); + $rootScope.isBusy = false; + $scope.$apply(); + } } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); + $rootScope.showErrors(["Please choose file"]); } }; + }, + ], +}); - ctrl.update = function (data) { - ctrl.onUpdate({ - data: data, - }); - }; - - ctrl.delete = function (data) { - ctrl.onDelete({ - data: data, - }); - }; +"use strict"; +app.controller("MixNavigationController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "MediaService", + "ApiService", + "CommonService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + service, + apiService, + commonService + ) { + BaseCtrl.call( + this, + $scope, + $rootScope, + $routeParams, + ngAppSettings, + service + ); - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - ctrl.minPriority = ctrl.mixDatabaseNavs[0].priority; - }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex + 1, 1); + $scope.viewmodel = { + title: "", + description: "", + status: "Published", + mediaFile: { + file: null, + fullPath: "", + folderName: "Media", + fileFolder: "", + fileName: "", + extension: "", + content: "", + fileStream: "", + }, + }; + $scope.relatedMedias = []; + $scope.uploadMedia = async function () { + $rootScope.isBusy = true; + var resp = await service.uploadMedia($scope.mediaFile); + if (resp && resp.success) { + $scope.activedMedia = resp.data; + $scope.getList(); + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); } - var arrNavs = []; - angular.forEach(ctrl.mixDatabaseNavs, function (e, i) { - e.priority = ctrl.minPriority + i; - var keys = { - parentId: e.parentId, - parentType: e.parentType, - id: e.id, - }; - var properties = { - priority: e.priority, - }; - arrNavs.push({ - keys: keys, - properties: properties, - }); - }); - navService.saveProperties("portal", arrNavs).then((resp) => { + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.selectFile = function (file, errFiles) { + if (file !== undefined && file !== null) { + $scope.mediaFile.folder = "Media"; + $scope.mediaFile.file = file; + $scope.getBase64(file); + } + }; + $scope.getBase64 = function (file) { + if (file !== null && $scope.postedFile) { + $rootScope.isBusy = true; + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function () { + var index = reader.result.indexOf(",") + 1; + var base64 = reader.result.substring(index); + $scope.activedMedia.mediaFile.fileName = $rootScope.generateKeyword( + file.name.substring(0, file.name.lastIndexOf(".")), + "-" + ); + $scope.activedMedia.mediaFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + $scope.activedMedia.mediaFile.fileStream = reader.result; $rootScope.isBusy = false; $scope.$apply(); - }); - }; - }, - ], -}); + }; + reader.onerror = function (error) { + $rootScope.showErrors([error]); + $rootScope.isBusy = false; + }; + } else { + return null; + } + }; + $scope.togglePreview = function (item) { + item.isPreview = item.isPreview === undefined ? true : !item.isPreview; + }; + $scope.clone = async function (id) { + $rootScope.isBusy = true; + var resp = await service.cloneMedia(id); + if (resp && resp.success) { + $scope.activedMedia = resp.data; + $rootScope.showMessage("Update successfully!", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + //$location.path('/admin/media/details/' + resp.data.id); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.saveSuccessCallback = function () { + $scope.getList(); + }; + $scope.removeCallback = function () { + $scope.getList(); + }; + }, +]); -modules.component("mixFileExtract", { +modules.component("mixDatabaseNavValues", { templateUrl: - "/mix-app/views/app-portal/components/mix-file-extract/view.html", + "/mix-app/views/app-portal/components/mix-database-nav-values/view.html", bindings: { - folder: "=?", - accept: "=?", - onFail: "&?", - onSuccess: "&?", + mixDatabaseId: "=", + mixDatabaseName: "=", + guidParentId: "=", + parentType: "=", + columns: "=?", + header: "=", + data: "=?", + maxCol: "=?", + createUrl: "=?", + updateUrl: "=?", + onUpdate: "&?", + onDelete: "&?", }, controller: [ "$rootScope", "$scope", "ngAppSettings", - "FileServices", - function ($rootScope, $scope, ngAppSettings, fileService) { + "RestRelatedAttributeDataPortalService", + "RestMixDatabaseColumnPortalService", + function ($rootScope, $scope, ngAppSettings, navService, columnService) { var ctrl = this; - ctrl.mediaFile = {}; - ctrl.isAdmin = $rootScope.isAdmin; - ctrl.mediaNavs = []; - ctrl.$onInit = function () { - ctrl.id = Math.floor(Math.random() * 100); - }; - ctrl.selectFile = function (files) { - if (files !== undefined && files !== null && files.length > 0) { - const file = files[0]; - ctrl.file = file; - ctrl.mediaFile.folder = ctrl.folder ? ctrl.folder : "Media"; - ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; - ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; - ctrl.mediaFile.file = file; - if (ctrl.auto == "true") { - ctrl.uploadFile(file); - } else { - ctrl.getBase64(file); - } - } - }; + ctrl.selectedProp = null; + ctrl.request = angular.copy(ngAppSettings.restRequest); + ctrl.request.orderBy = "Priority"; + ctrl.request.query = "{}"; - ctrl.getBase64 = function (file) { - if (file !== null) { - $rootScope.isBusy = true; - var reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function () { - if (ctrl.mediaFile) { - ctrl.mediaFile.fileName = file.name.substring( - 0, - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.fileStream = reader.result; - } - $rootScope.isBusy = false; - $scope.$apply(); - }; - reader.onerror = function (error) { - $rootScope.isBusy = false; - $rootScope.showErrors([error]); - }; - } else { - return null; + ctrl.request.direction = 0; + ctrl.mixConfigurations = $rootScope.globalSettings; + ctrl.$onInit = async function () { + ctrl.maxCol = ctrl.maxCol || 3; + if (!ctrl.createUrl) { + ctrl.createUrl = "/admin/mix-database-data/create"; } - }; - - ctrl.uploadFile = async function () { - if (ctrl.file) { - $rootScope.isBusy = true; - var response = await fileService.extractFile(ctrl.file, ctrl.folder); - if (response) { - if (ctrl.onSuccess) { - ctrl.onSuccess(); - } - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(["Cannot upload file"]); - $rootScope.isBusy = false; + if (!ctrl.updateUrl) { + ctrl.updateUrl = "/admin/mix-database-data/details"; + } + if (!ctrl.columns) { + var getFields = await columnService.initData( + ctrl.mixDatabaseName || ctrl.mixDatabaseId + ); + if (getFields.success) { + ctrl.columns = getFields.data; $scope.$apply(); } - } else { - $rootScope.showErrors(["Please choose file"]); + } + if (!ctrl.data) { + ctrl.loadData(); } }; - }, - ], -}); -modules.component("mixFileUpload", { - templateUrl: "/mix-app/views/app-portal/components/mix-file-upload/view.html", - bindings: { - folder: "=?", - accept: "=?", - onFail: "&?", - onSuccess: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "FileServices", - function ($rootScope, $scope, ngAppSettings, fileService) { - var ctrl = this; - ctrl.mediaFile = {}; - ctrl.isAdmin = $rootScope.isAdmin; - ctrl.mediaNavs = []; - ctrl.$onInit = function () { - ctrl.id = Math.floor(Math.random() * 100); + ctrl.update = function (data) { + ctrl.onUpdate({ data: data }); }; - ctrl.selectFile = function (files) { - if (files !== undefined && files !== null && files.length > 0) { - const file = files[0]; - ctrl.file = file; - ctrl.mediaFile.folder = ctrl.folder ? ctrl.folder : "Media"; - ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; - ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; - ctrl.mediaFile.file = file; - if (ctrl.auto == "true") { - ctrl.uploadFile(file); - } else { - ctrl.getBase64(file); - } - } + + ctrl.delete = function (data) { + ctrl.onDelete({ data: data }); }; - ctrl.getBase64 = function (file) { - if (file !== null) { - $rootScope.isBusy = true; - var reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function () { - if (ctrl.mediaFile) { - ctrl.mediaFile.fileName = file.name.substring( - 0, - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.fileStream = reader.result; - } - $rootScope.isBusy = false; - $scope.$apply(); - }; - reader.onerror = function (error) { - $rootScope.isBusy = false; - $rootScope.showErrors([error]); - }; + ctrl.filterData = function (item, attributeName) { + return $rootScope.findObjectByKey( + item.data, + "attributeName", + attributeName + ); + }; + + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; + ctrl.minPriority = ctrl.data.items[0].priority; + }; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.data.items.splice(ctrl.dragStartIndex, 1); } else { - return null; + ctrl.data.items.splice(ctrl.dragStartIndex + 1, 1); } + angular.forEach(ctrl.data.items, function (e, i) { + e.priority = ctrl.minPriority + i; + navService.saveFields(e.id, { priority: e.priority }).then((resp) => { + $rootScope.isBusy = false; + $scope.$apply(); + }); + }); }; - ctrl.uploadFile = async function () { - if (ctrl.file) { - $rootScope.isBusy = true; - var response = await fileService.uploadFile(ctrl.file, ctrl.folder); - if (response) { - if (ctrl.onSuccess) { - ctrl.onSuccess(); + ctrl.loadData = function () { + ctrl.request.mixDatabaseId = ctrl.mixDatabaseId || 0; + ctrl.request.mixDatabaseName = ctrl.mixDatabaseName || null; + ctrl.request.guidParentId = ctrl.guidParentId; + ctrl.request.intParentId = ctrl.intParentId; + ctrl.request.parentType = ctrl.parentType; + navService.getList(ctrl.request).then((resp) => { + if (resp) { + ctrl.data = resp.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors("Failed"); } - $rootScope.showMessage("success", "success"); + ctrl.refData = []; $rootScope.isBusy = false; $scope.$apply(); + } + }); + }; + ctrl.updateData = function (nav) { + $rootScope.goToPath( + `${ctrl.updateUrl}?dataContentId=${nav.childDataContent.id}&mixDatabaseId=${nav.mixDatabaseId}&guidParentId=${ctrl.guidParentId}&parentType=${ctrl.parentType}` + ); + // ctrl.refDataModel = nav; + // var e = $(".pane-form-" + ctrl.mixDatabaseDataValue.column.referenceId)[0]; + // angular.element(e).triggerHandler('click'); + // $location.url('/admin/mix-database-data/details?dataContentId='+ item.id +'&mixDatabaseId=' + item.mixDatabaseId+'&parentType=' + item.parentType+'&parentId=' + item.parentId); + }; + ctrl.saveData = function (data) { + $rootScope.isBusy = true; + ctrl.refDataModel.data = data; + dataService.save("portal", data).then((resp) => { + if (resp.success) { + ctrl.refDataModel.id = resp.data.id; + ctrl.refDataModel.data = resp.data; + navService.save("portal", ctrl.refDataModel).then((resp) => { + if (resp.success) { + var tmp = $rootScope.findObjectByKey( + ctrl.refData, + ["parentId", "parentType", "id"], + [resp.data.parentId, resp.data.parentType, resp.data.id] + ); + if (!tmp) { + ctrl.refData.push(resp.data); + } + ctrl.refDataModel = angular.copy(ctrl.defaultDataModel); + var e = $( + ".pane-data-" + ctrl.mixDatabaseDataValue.column.referenceId + )[0]; + angular.element(e).triggerHandler("click"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }); } else { - $rootScope.showErrors(['Cannot upload file']); + $rootScope.showMessage("failed"); $rootScope.isBusy = false; $scope.$apply(); } - } else { - $rootScope.showErrors(["Please choose file"]); - } + }); + }; + ctrl.removeData = async function (nav) { + $rootScope.showConfirm( + ctrl, + "removeDataConfirmed", + [nav], + null, + "Remove", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); }; - }, - ], -}); - -"use strict"; -app.controller("MixNavigationController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "MediaService", - "ApiService", - "CommonService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - service, - apiService, - commonService - ) { - BaseCtrl.call( - this, - $scope, - $rootScope, - $routeParams, - ngAppSettings, - service - ); - - $scope.viewmodel = { - title: "", - description: "", - status: "Published", - mediaFile: { - file: null, - fullPath: "", - folderName: "Media", - fileFolder: "", - fileName: "", - extension: "", - content: "", - fileStream: "", - }, - }; - $scope.relatedMedias = []; - $scope.uploadMedia = async function () { - $rootScope.isBusy = true; - var resp = await service.uploadMedia($scope.mediaFile); - if (resp && resp.success) { - $scope.activedMedia = resp.data; - $scope.getList(); - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.selectFile = function (file, errFiles) { - if (file !== undefined && file !== null) { - $scope.mediaFile.folder = "Media"; - $scope.mediaFile.file = file; - $scope.getBase64(file); - } - }; - $scope.getBase64 = function (file) { - if (file !== null && $scope.postedFile) { + ctrl.removeDataConfirmed = async function (nav) { $rootScope.isBusy = true; - var reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = function () { - var index = reader.result.indexOf(",") + 1; - var base64 = reader.result.substring(index); - $scope.activedMedia.mediaFile.fileName = $rootScope.generateKeyword( - file.name.substring(0, file.name.lastIndexOf(".")), - "-" - ); - $scope.activedMedia.mediaFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - $scope.activedMedia.mediaFile.fileStream = reader.result; + var result = await navService.delete([nav.id]); + if (result.success) { + $rootScope.removeObjectByKey(ctrl.data.items, "id", nav.id); $rootScope.isBusy = false; $scope.$apply(); - }; - reader.onerror = function (error) { - $rootScope.showErrors([error]); + } else { + $rootScope.showMessage("failed"); $rootScope.isBusy = false; - }; - } else { - return null; - } - }; - $scope.togglePreview = function (item) { - item.isPreview = item.isPreview === undefined ? true : !item.isPreview; - }; - $scope.clone = async function (id) { - $rootScope.isBusy = true; - var resp = await service.cloneMedia(id); - if (resp && resp.success) { - $scope.activedMedia = resp.data; - $rootScope.showMessage("Update successfully!", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - //$location.path('/admin/media/details/' + resp.data.id); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.$apply(); } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.saveSuccessCallback = function () { - $scope.getList(); - }; - $scope.removeCallback = function () { - $scope.getList(); - }; - }, -]); + }; + ctrl.view = function (item) { + var obj = { + columns: ctrl.columns, + item: item, + }; + $rootScope.preview("mix-database-data", obj, null, "modal-lg"); + }; + }, + ], +}); modules.component("mixSelectIcons", { templateUrl: @@ -15244,46 +15163,6 @@ modules.component("navigators", { ], }); -modules.component("portalThemeSettings", { - templateUrl: - "/mix-app/views/app-portal/components/portal-theme-settings/view.html", - bindings: { - showLink: "=", - }, - controller: [ - "$rootScope", - "$scope", - "AppSettingsServices", - function ($rootScope, $scope, appSettingsServices) { - var ctrl = this; - this.$onInit = function () { - ctrl.portalThemeSettings = - $rootScope.globalSettings.portalThemeSettings; - }; - ctrl.applyThemeSettings = function () { - $rootScope.globalSettings.portalThemeSettings = - ctrl.portalThemeSettings; - }; - ctrl.saveThemeSettings = async function () { - var resp = await appSettingsServices.saveAppSettings( - "PortalThemeSettings", - ctrl.portalThemeSettings - ); - if (resp && resp.success) { - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $scope.$apply(); - } - }; - }, - ], -}); - modules.component("propertiesStructure", { templateUrl: "/mix-app/views/app-portal/components/properties-structure/view.html", @@ -15415,6 +15294,46 @@ modules.component("propertiesStructure", { }, }); +modules.component("portalThemeSettings", { + templateUrl: + "/mix-app/views/app-portal/components/portal-theme-settings/view.html", + bindings: { + showLink: "=", + }, + controller: [ + "$rootScope", + "$scope", + "AppSettingsServices", + function ($rootScope, $scope, appSettingsServices) { + var ctrl = this; + this.$onInit = function () { + ctrl.portalThemeSettings = + $rootScope.globalSettings.portalThemeSettings; + }; + ctrl.applyThemeSettings = function () { + $rootScope.globalSettings.portalThemeSettings = + ctrl.portalThemeSettings; + }; + ctrl.saveThemeSettings = async function () { + var resp = await appSettingsServices.saveAppSettings( + "PortalThemeSettings", + ctrl.portalThemeSettings + ); + if (resp && resp.success) { + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $scope.$apply(); + } + }; + }, + ], +}); + modules.component("propertiesValue", { templateUrl: "/mix-app/views/app-portal/components/properties-value/view.html", @@ -15652,6 +15571,22 @@ modules.component("serviceHubPortal", { ], }); +modules.component("toastHelper", { + templateUrl: + "/mix-app/views/app-portal/components/toast-helper/toast-helper.html", + bindings: { + url: "=?", + title: "=?", + }, + controller: [ + "$rootScope", + function ($rootScope) { + var ctrl = this; + ctrl.visible = $rootScope.visible; + }, + ], +}); + modules.component("templateEditor", { templateUrl: "/mix-app/views/app-portal/components/template-editor/templateEditor.html", @@ -15802,22 +15737,6 @@ modules.component("templateEditor", { ], }); -modules.component("toastHelper", { - templateUrl: - "/mix-app/views/app-portal/components/toast-helper/toast-helper.html", - bindings: { - url: "=?", - title: "=?", - }, - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.visible = $rootScope.visible; - }, - ], -}); - modules.component("urlAlias", { templateUrl: "/mix-app/views/app-portal/components/url-alias/url-alias.html", controller: [ diff --git a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/components/_layout-portal-modals/view.html b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/components/_layout-portal-modals/view.html index 36814739f..dba5de964 100644 --- a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/components/_layout-portal-modals/view.html +++ b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/components/_layout-portal-modals/view.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html index 5ee6294fe..059614c21 100644 --- a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html +++ b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html @@ -1 +1 @@ -
DatabaseNameTypeAuthor
{{item.displayName}}{{item.systemName}}{{item.type}}{{item.createdBy}}🟢 🟡 🔴 ⚫️
\ No newline at end of file +
DatabaseNameTypeAuthor
{{item.displayName}}{{item.systemName}}{{item.type}}{{item.createdBy}}🟢 🟡 🔴 ⚫️
\ No newline at end of file diff --git a/src/modules/mix.portal/Controllers/MixDatabaseController.cs b/src/modules/mix.portal/Controllers/MixDatabaseController.cs index 093ab228c..79342dda3 100644 --- a/src/modules/mix.portal/Controllers/MixDatabaseController.cs +++ b/src/modules/mix.portal/Controllers/MixDatabaseController.cs @@ -17,7 +17,7 @@ public MixDatabaseController( TranslatorService translator, MixIdentityService mixIdentityService, UnitOfWorkInfo cmsUow, - IQueueService queueService, + IQueueService queueService, IMixDbService mixDbService) : base(httpContextAccessor, configuration, mixService, translator, mixIdentityService, cmsUow, queueService) { @@ -35,6 +35,21 @@ public async Task> GetByName(string name) return NotFound(); } + [MixAuthorize(MixRoles.Owner)] + [HttpGet("duplicate/{id}")] + public async Task> Duplicate(int id, CancellationToken cancellationToken = default) + { + var data = await GetById(id); + if (data != null) + { + data.Duplicate(); + var newId = await CreateHandlerAsync(data, cancellationToken); + var result = await GetById(newId); + return Ok(result); + } + throw new MixException(MixErrorStatus.NotFound, id); + } + [MixAuthorize(MixRoles.Owner)] [HttpGet("migrate/{name}")] public async Task Migrate(string name) diff --git a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs index 82ca75cea..7436f241f 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs @@ -3,8 +3,7 @@ namespace Mix.Lib.ViewModels { [GenerateRestApiController] - public sealed class MixDatabaseViewModel - : TenantDataViewModelBase + public sealed class MixDatabaseViewModel : TenantDataViewModelBase { #region Properties [Required] @@ -114,5 +113,15 @@ protected override async Task DeleteHandlerAsync(CancellationToken cancellationT } #endregion + + public override void Duplicate() + { + Id = default; + DisplayName = $"Duplicated {DisplayName}"; + SystemName = $"duplicated{SystemName}"; + + Columns.ForEach(p => p.Id = 0); + Relationships.ForEach(p => p.Id = 0); + } } } From 49b0d83a5375b6e2be822f5245288c7f5bf91638 Mon Sep 17 00:00:00 2001 From: "phat.truong" Date: Wed, 22 Mar 2023 18:28:27 +0700 Subject: [PATCH 2/8] Add duplicate function in heart --- src/platform/core/mix-heart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/core/mix-heart b/src/platform/core/mix-heart index b94616e9a..0376b1e40 160000 --- a/src/platform/core/mix-heart +++ b/src/platform/core/mix-heart @@ -1 +1 @@ -Subproject commit b94616e9ae16974ffcbd9af9268a8eac2196c283 +Subproject commit 0376b1e40c464a6289e6a7ecb69ecf3747e6be97 From 8cdf75c6efc0d0a442cceda30fde5ef490ad6991 Mon Sep 17 00:00:00 2001 From: "phat.truong" Date: Wed, 22 Mar 2023 18:30:51 +0700 Subject: [PATCH 3/8] Update css class --- .../mix-app/views/app-portal/pages/mix-database/list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html index 059614c21..d3bb2675d 100644 --- a/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html +++ b/src/applications/Mixcore/wwwroot/mix-app/views/app-portal/pages/mix-database/list.html @@ -1 +1 @@ -
DatabaseNameTypeAuthor
{{item.displayName}}{{item.systemName}}{{item.type}}{{item.createdBy}}🟢 🟡 🔴 ⚫️
\ No newline at end of file +
DatabaseNameTypeAuthor
{{item.displayName}}{{item.systemName}}{{item.type}}{{item.createdBy}}🟢 🟡 🔴 ⚫️
\ No newline at end of file From 6b558c08c8cb68e35492bd518037435f609c8abb Mon Sep 17 00:00:00 2001 From: Phat Truong Date: Thu, 23 Mar 2023 10:17:55 +0700 Subject: [PATCH 4/8] Delete entity relationship --- .../MixDatabaseRelationshipViewModel.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs index c6a9a1a6b..c1f93c32c 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; namespace Mix.Lib.ViewModels { @@ -81,20 +82,21 @@ protected override async Task SaveEntityRelationshipAsync(MixDatabaseRelationshi } } - //protected override async Task DeleteHandlerAsync(CancellationToken cancellationToken = default) - //{ - // var leftDb = Context.MixDatabase.Find(ParentId); - // string leftColName = $"{leftDb.SystemName}Id"; - // var rightDb = Context.MixDatabase.Find(ChildId); - // string rightColName = $"{rightDb.SystemName}Id"; - // await MixDatabaseColumnViewModel.GetRepository(UowInfo) - // .DeleteManyAsync(m => - // (m.MixDatabaseId == ParentId && m.SystemName == rightColName) - // || (m.MixDatabaseId == ChildId && m.SystemName == leftColName), - // cancellationToken); + protected override async Task DeleteEntityRelationshipAsync(CancellationToken cancellationToken = default) + { + string parentColIdName = $"{SourceDatabaseName.ToTitleCase()}Id"; + var refColumn = await Context.MixDatabaseColumn + .FirstOrDefaultAsync(m => + m.MixDatabaseName == DestinateDatabaseName + && m.SystemName == parentColIdName + && m.DataType == MixDataType.Reference, + cancellationToken); - // await base.DeleteHandlerAsync(cancellationToken); - //} + if (refColumn != null) + { + Context.MixDatabaseColumn.Remove(refColumn); + } + } #endregion } From fb7d51b52495c75e35fddf6ffdd8f8e70cba775b Mon Sep 17 00:00:00 2001 From: Phat Truong Date: Thu, 23 Mar 2023 10:19:39 +0700 Subject: [PATCH 5/8] update heart --- src/platform/core/mix-heart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/core/mix-heart b/src/platform/core/mix-heart index 0376b1e40..391086239 160000 --- a/src/platform/core/mix-heart +++ b/src/platform/core/mix-heart @@ -1 +1 @@ -Subproject commit 0376b1e40c464a6289e6a7ecb69ecf3747e6be97 +Subproject commit 39108623956deed662159b3167599f78069b2094 From 2aaeb83add41877e53f24a28571cd6a6f0baf2ad Mon Sep 17 00:00:00 2001 From: "phat.truong" Date: Thu, 23 Mar 2023 14:37:48 +0700 Subject: [PATCH 6/8] Add validation before creating database --- .../MixDatabaseRelationshipViewModel.cs | 28 +++++-------------- .../ViewModels/MixDatabaseViewModel.cs | 20 ++++++++++--- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs index c1f93c32c..902652266 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseRelationshipViewModel.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; namespace Mix.Lib.ViewModels { @@ -13,6 +14,9 @@ public sealed class MixDatabaseRelationshipViewModel public string SourceDatabaseName { get; set; } public string DestinateDatabaseName { get; set; } public MixDatabaseRelationshipType Type { get; set; } + + [JsonIgnore] + public string ReferenceColumnName => $"{SourceDatabaseName.ToTitleCase()}Id"; #endregion #region Constructors @@ -36,7 +40,6 @@ public MixDatabaseRelationshipViewModel(MixDatabaseRelationship entity, UnitOfWo #region Overrides public override async Task Validate(CancellationToken cancellationToken) { - if (Repository.Table.Any(m => !m.Id.Equals(Id) && m.ParentId.Equals(ParentId) && m.ChildId.Equals(ChildId))) { IsValid = false; @@ -63,8 +66,7 @@ public override async Task Validate(CancellationToken cancellationToken) protected override async Task SaveEntityRelationshipAsync(MixDatabaseRelationship parentEntity, CancellationToken cancellationToken = default) { - string parentColIdName = $"{SourceDatabaseName.ToTitleCase()}Id"; - if (!Context.MixDatabaseColumn.Any(m => m.MixDatabaseName == DestinateDatabaseName && m.SystemName == parentColIdName)) + if (!Context.MixDatabaseColumn.Any(m => m.MixDatabaseName == DestinateDatabaseName && m.SystemName == ReferenceColumnName)) { var srcDb = Context.MixDatabase.FirstOrDefault(m => m.SystemName == SourceDatabaseName); var destDb = Context.MixDatabase.FirstOrDefault(m => m.SystemName == DestinateDatabaseName); @@ -74,30 +76,14 @@ protected override async Task SaveEntityRelationshipAsync(MixDatabaseRelationshi MixDatabaseId = destDb.Id, DataType = MixDataType.Reference, CreatedBy = CreatedBy, - DisplayName = parentColIdName.ToTitleCase(), - SystemName = parentColIdName + DisplayName = ReferenceColumnName.ToTitleCase(), + SystemName = ReferenceColumnName }; await refCol.SaveAsync(cancellationToken); } } - protected override async Task DeleteEntityRelationshipAsync(CancellationToken cancellationToken = default) - { - string parentColIdName = $"{SourceDatabaseName.ToTitleCase()}Id"; - var refColumn = await Context.MixDatabaseColumn - .FirstOrDefaultAsync(m => - m.MixDatabaseName == DestinateDatabaseName - && m.SystemName == parentColIdName - && m.DataType == MixDataType.Reference, - cancellationToken); - - if (refColumn != null) - { - Context.MixDatabaseColumn.Remove(refColumn); - } - } - #endregion } } diff --git a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs index 7436f241f..9c0b4b8ae 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; namespace Mix.Lib.ViewModels { @@ -24,7 +25,6 @@ public sealed class MixDatabaseViewModel : TenantDataViewModelBase p.SystemName == SystemName, cancellationToken)) + { + IsValid = false; + Errors.Add(new ValidationResult("Database Existed")); + } + + await base.Validate(cancellationToken); + } + public override async Task ExpandView(CancellationToken cancellationToken = default) { Columns = await MixDatabaseColumnViewModel.GetRepository(UowInfo).GetListAsync(c => c.MixDatabaseId == Id, cancellationToken); @@ -120,8 +132,8 @@ public override void Duplicate() DisplayName = $"Duplicated {DisplayName}"; SystemName = $"duplicated{SystemName}"; - Columns.ForEach(p => p.Id = 0); - Relationships.ForEach(p => p.Id = 0); + Columns.ForEach(p => p.Id = default); + Relationships.ForEach(p => p.Id = default); } } } From b865cf3a73ae1d5b355ddc638eeabea5a73268c9 Mon Sep 17 00:00:00 2001 From: "phat.truong" Date: Thu, 23 Mar 2023 18:20:46 +0700 Subject: [PATCH 7/8] Remove validation on MixDatabaseViewModel --- .../mix.library/ViewModels/MixDatabaseViewModel.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs index 9c0b4b8ae..b1883dc23 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs @@ -40,17 +40,6 @@ public MixDatabaseViewModel(MixDatabase entity, UnitOfWorkInfo uowInfo = null) #region Overrides - public override async Task Validate(CancellationToken cancellationToken) - { - if (await Context.MixDatabase.AnyAsync(p => p.SystemName == SystemName, cancellationToken)) - { - IsValid = false; - Errors.Add(new ValidationResult("Database Existed")); - } - - await base.Validate(cancellationToken); - } - public override async Task ExpandView(CancellationToken cancellationToken = default) { Columns = await MixDatabaseColumnViewModel.GetRepository(UowInfo).GetListAsync(c => c.MixDatabaseId == Id, cancellationToken); From a77ebd493de736543fbf388b360ac3c3389d1766 Mon Sep 17 00:00:00 2001 From: Phat Truong Date: Thu, 23 Mar 2023 20:37:21 +0700 Subject: [PATCH 8/8] Add mixdbvm validation --- .../mix.library/ViewModels/MixDatabaseViewModel.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs index b1883dc23..35f985cdb 100644 --- a/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs +++ b/src/platform/mix.library/ViewModels/MixDatabaseViewModel.cs @@ -40,6 +40,17 @@ public MixDatabaseViewModel(MixDatabase entity, UnitOfWorkInfo uowInfo = null) #region Overrides + public override async Task Validate(CancellationToken cancellationToken) + { + if (await Context.MixDatabase.AnyAsync(p => p.Id != Id && p.SystemName == SystemName, cancellationToken)) + { + IsValid = false; + Errors.Add(new ValidationResult("Database name must be unique.")); + } + + await base.Validate(cancellationToken); + } + public override async Task ExpandView(CancellationToken cancellationToken = default) { Columns = await MixDatabaseColumnViewModel.GetRepository(UowInfo).GetListAsync(c => c.MixDatabaseId == Id, cancellationToken);