diff --git a/src/Mix.Cms.Web/appsettings.json b/src/Mix.Cms.Web/appsettings.json index f843e9242..7bf7b9fa4 100644 --- a/src/Mix.Cms.Web/appsettings.json +++ b/src/Mix.Cms.Web/appsettings.json @@ -1,12 +1,12 @@ { "ConnectionStrings": { - "MixAccountConnection": "Data Source=MixContent\\mix-cms.db", - "MixCmsConnection": "Data Source=MixContent\\mix-cms.db", - "MixMessengerConnection": "Data Source=MixContent\\mix-cms.db" + "MixAccountConnection": null, + "MixCmsConnection": null, + "MixMessengerConnection": null }, "GlobalSettings": { - "IsInit": false, - "InitStatus": 3, + "IsInit": true, + "InitStatus": 0, "IsMaintenance": false, "IsRewrite": true, "IsHttps": false, @@ -35,8 +35,8 @@ "TagPageSize": "20", "SearchPageSize": "20", "IsEncryptApi": true, - "ApiEncryptKey": "VlZRMHZ6dkdiSitVOWtuNE9DZjVNdz09LGRScUg4cDE2OE1aTDA2RytwZFlzdnEvYk53WThFcVNMWnZnZXNESWxpVGM9", - "LastUpdateConfiguration": "2022-04-07T08:13:19.4181642Z", + "ApiEncryptKey": "RHZhMEFvckY0VUF3Ynd2YUZZTnRIdz09LGx3dk82QlR0WHlPUG5FWC8rUFV2bU1pdUpIMnVQTEF5TW9kMFpPdU5aMlU9", + "LastUpdateConfiguration": null, "DatabaseProvider": "SQLITE", "AllowedHosts": [], "Smtp": { @@ -65,14 +65,14 @@ "fontFamily": "", "fontSizeH1": "16", "fontSize": "12" - }, - "MixcoreVersion": "1.0.1" + } }, + "MixConfigurations": { "IsCache": true, "MixCacheMode": "Json", - "MixCacheConnectionString": "Data Source=MixContent\\mix-cms.db", - "MixCacheDbProvider": "SQLITE", + "MixCacheConnectionString": "", + "MixCacheDbProvider": "", "MixCacheFolder": "MixContent/cache", "JsonDataFolder": "MixContent/data", "MixLogsFolder": "MixContent/logs", @@ -106,7 +106,7 @@ "ValidateIssuerSigningKey": true, "TokenType": "Bearer", "Audience": "mix-core", - "SecretKey": "5f631ca7406b46b6b0a8e143bad0f203", + "SecretKey": "mixcore-secret-key", "Issuer": "mix-core", "Issuers": "mix-core", "Audiences": "mix-core", @@ -140,29 +140,20 @@ "OriginKey": "" } }, - "Translator": { - "en-us": {} - }, + "Translator": {}, "LocalSettings": { "en-us": { - "SiteName": "test import", + "ContactAddress": "", + "ContactEmail": "", + "ContactPhone": "", + "Facebook": "", + "FacebookAppId": "", + "Favicon": "", "LanguageVersion": "1", + "Logo": "", "SettingVersion": "1", - "ThemeName": "test-import", - "ThemeFolder": "test-import", - "ThemeId": "1", - "DateTimeFormat": "dd-MM-yyyy HH:mm:ss", - "StartWeekOn": "Monday", - "DefaultThumbnailImgWidth": "1000", - "DefaultThumbnailImgHeight": "608", - "DefaultFeatureImgWidth": "2000", - "DefaultFeatureImgHeight": "1216", - "SiteTitle": "Mixcore Casper Theme", - "SiteCoverImage": "", - "SiteLogo": "/mix-content/assets/test-import/uploads/2021-02/mixcorewhite-637498510478815515.png", - "SiteDescription": "The professional publishing platform", - "post_image_width": "", - "post_image_height": "" + "Theme": "Default", + "ThemeId": "1" } }, "Logging": { @@ -180,11 +171,10 @@ "Language": "en-us", "EPPlus": { "ExcelPackage": { - "LicenseContext": "NonCommercial" + "LicenseContext": "NonCommercial" //The license context used } }, "Quartz": { "quartz.scheduler.instanceName": "Mixcore Cms Scheduler" - }, - "Smtp": {} -} + } +} \ No newline at end of file diff --git a/src/Mix.Cms.Web/wwwroot/mix-app/js/app-portal.min.js b/src/Mix.Cms.Web/wwwroot/mix-app/js/app-portal.min.js index 598b6c1c3..608debd34 100644 --- a/src/Mix.Cms.Web/wwwroot/mix-app/js/app-portal.min.js +++ b/src/Mix.Cms.Web/wwwroot/mix-app/js/app-portal.min.js @@ -1,4 +1,4 @@ -/* Wed Apr 13 2022 12:51:29 GMT+0700 (Indochina Time) */"use strict"; +/* Wed Apr 13 2022 14:32:08 GMT+0700 (Indochina Time) */"use strict"; var app = angular.module("MixPortal", [ "angularCroppie", "ui.bootstrap", @@ -1226,6 +1226,97 @@ app.factory("CustomerServices", [ }, ]); +"use strict"; +app.controller("DashboardController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$timeout", + "$location", + "DashboardServices", + function ( + $scope, + $rootScope, + ngAppSettings, + $timeout, + $location, + dashboardServices + ) { + $scope.pageClass = "page-dashboard"; + $(".side-nav li").removeClass("active"); + $(".side-nav .page-dashboard").addClass("active"); + $scope.data = { + totalPage: 0, + totalPost: 0, + totalProduct: 0, + totalUser: 0, + }; + $scope.users = []; + $scope.$on("$viewContentLoaded", function () { + $rootScope.isBusy = false; + }); + $scope.getDashboardInfo = async function () { + $rootScope.isBusy = true; + var response = await dashboardServices.getDashboardInfo(); + if (response.isSucceed) { + // $('#mainSection').removeClass('card'); + $scope.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + // $scope.getChart(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.getChart = function () { + var ctx = document.getElementById("myChart"); + var myChart = new Chart(ctx, { + // type: 'pie', + // data: { + // labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], + // datasets: [{ + // label: "Population (millions)", + // backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"], + // data: [2478,5267,734,784,433] + // }] + // }, + // options: { + // title: { + // display: true, + // text: 'Predicted world population (millions) in 2050' + // } + // } + }); + }; + }, +]); + +"use strict"; +app.factory("DashboardServices", [ + "$rootScope", + "$http", + "ApiService", + "CommonService", + function ($rootScope, $http, apiService, commonService) { + //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; + + var usersServiceFactory = {}; + var apiUrl = "/portal/" + $rootScope.localizeSettings.lang; + var _getDashboardInfo = async function () { + var req = { + method: "GET", + url: apiUrl + "/dashboard", + }; + return await apiService.getApiResult(req); + }; + + usersServiceFactory.getDashboardInfo = _getDashboardInfo; + return usersServiceFactory; + }, +]); + "use strict"; app.controller("FileController", [ "$scope", @@ -1458,152 +1549,6 @@ app.factory("FileServices", [ }, ]); -"use strict"; -app.controller("ImportFileController", [ - "$scope", - "$rootScope", - "ImportFileServices", - "TranslatorService", - "GlobalSettingsService", - function ( - $scope, - $rootScope, - service, - translatorService, - GlobalSettingsService - ) { - $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.isSucceed) { - $scope.viewmodel = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - }, -]); - -"use strict"; -app.factory("ImportFileServices", [ - "$rootScope", - "BaseService", - function ($rootScope, baseService) { - //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; - - var serviceFactory = {}; - - 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.saveImportFile = _saveImportFile; - return serviceFactory; - }, -]); - -"use strict"; -app.controller("DashboardController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$timeout", - "$location", - "DashboardServices", - function ( - $scope, - $rootScope, - ngAppSettings, - $timeout, - $location, - dashboardServices - ) { - $scope.pageClass = "page-dashboard"; - $(".side-nav li").removeClass("active"); - $(".side-nav .page-dashboard").addClass("active"); - $scope.data = { - totalPage: 0, - totalPost: 0, - totalProduct: 0, - totalUser: 0, - }; - $scope.users = []; - $scope.$on("$viewContentLoaded", function () { - $rootScope.isBusy = false; - }); - $scope.getDashboardInfo = async function () { - $rootScope.isBusy = true; - var response = await dashboardServices.getDashboardInfo(); - if (response.isSucceed) { - // $('#mainSection').removeClass('card'); - $scope.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - // $scope.getChart(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.getChart = function () { - var ctx = document.getElementById("myChart"); - var myChart = new Chart(ctx, { - // type: 'pie', - // data: { - // labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], - // datasets: [{ - // label: "Population (millions)", - // backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"], - // data: [2478,5267,734,784,433] - // }] - // }, - // options: { - // title: { - // display: true, - // text: 'Predicted world population (millions) in 2050' - // } - // } - }); - }; - }, -]); - -"use strict"; -app.factory("DashboardServices", [ - "$rootScope", - "$http", - "ApiService", - "CommonService", - function ($rootScope, $http, apiService, commonService) { - //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; - - var usersServiceFactory = {}; - var apiUrl = "/portal/" + $rootScope.localizeSettings.lang; - var _getDashboardInfo = async function () { - var req = { - method: "GET", - url: apiUrl + "/dashboard", - }; - return await apiService.getApiResult(req); - }; - - usersServiceFactory.getDashboardInfo = _getDashboardInfo; - return usersServiceFactory; - }, -]); - "use strict"; app.controller("JsonDataController", [ "$scope", @@ -1820,26 +1765,81 @@ app.factory("JsonDataService", [ ]); "use strict"; -app.controller("LocalizeController", [ +app.controller("ImportFileController", [ "$scope", "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "LocalizeService", - "ApiService", - "CommonService", + "ImportFileServices", + "TranslatorService", + "GlobalSettingsService", function ( $scope, $rootScope, - ngAppSettings, - $routeParams, - $location, service, - commonService + translatorService, + GlobalSettingsService ) { - BaseRestCtrl.call( - this, + $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.isSucceed) { + $scope.viewmodel = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, +]); + +"use strict"; +app.factory("ImportFileServices", [ + "$rootScope", + "BaseService", + function ($rootScope, baseService) { + //var serviceBase = 'http://ngauthenticationapi.azurewebsites.net/'; + + var serviceFactory = {}; + + 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.saveImportFile = _saveImportFile; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("LocalizeController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "$location", + "LocalizeService", + "ApiService", + "CommonService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + $location, + service, + commonService + ) { + BaseRestCtrl.call( + this, $scope, $rootScope, $location, @@ -2035,22 +2035,24 @@ app.controller("loginController", [ ]); "use strict"; -app.controller("MixDatabaseDataController", [ +app.controller("MixDatabaseController", [ "$scope", "$rootScope", + "$location", "ngAppSettings", "$routeParams", - "$location", "RestMixDatabaseDataPortalService", "RestMixDatabaseColumnPortalService", + "RestMixDatabasePortalService", function ( $scope, $rootScope, + $location, ngAppSettings, $routeParams, - $location, - service, - columnService + databaseDataService, + databaseColumnService, + databaseService ) { BaseRestCtrl.call( this, @@ -2059,394 +2061,38 @@ app.controller("MixDatabaseDataController", [ $location, $routeParams, ngAppSettings, - service + databaseService ); - $scope.queries = {}; - $scope.data = {}; - $scope.exportAll = true; - $scope.localizeSettings = $rootScope.globalSettings; - // $scope.request.orderBy = "Priority"; - // $scope.request.direction = "Asc"; - $scope.filterType = "contain"; - $scope.defaultId = "default"; - $scope.importFile = { - file: null, - fullPath: "", - folder: "import", - title: "", - description: "", - }; - $scope.initRouteParams = () => { - $scope.requestKey = `request${$rootScope.generateKeyword( - $location.$$path, - "_" - )}_${$routeParams.mixDatabaseId}`; - $scope.request = $rootScope.getRequest($scope.requestKey); - if ($routeParams.mixDatabaseId) { - $scope.request.mixDatabaseId = $routeParams.mixDatabaseId; - } - $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; - $scope.request.filterType = $routeParams.filterType || "contain"; - $scope.request.compareType = $routeParams.compareType || "or"; - - $scope.mixDatabaseId = $routeParams.mixDatabaseId; - $scope.mixDatabaseName = $routeParams.mixDatabaseName; - $scope.mixDatabaseTitle = $routeParams.mixDatabaseTitle; - $scope.parentId = $routeParams.parentId; - $scope.parentType = $routeParams.parentType; - $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; - $scope.request.isGroup = $routeParams.isGroup || false; - if ($routeParams.backUrl) { - $scope.backUrl = decodeURIComponent($routeParams.backUrl); - } - if ($routeParams.dataId != $scope.defaultId) { - $scope.dataId = $routeParams.dataId; - } - - if ($scope.parentId && $scope.parentType) { - $scope.refDataModel = { - parentId: $scope.parentId, - parentType: $scope.parentType, - }; - } - }; - $scope.init = async function () { - $scope.initRouteParams(); - if ($scope.mixDatabaseName || $scope.mixDatabaseId) { - var getFields = await columnService.initData( - $scope.mixDatabaseName || $scope.mixDatabaseId - ); - if (getFields.isSucceed) { - $scope.columns = getFields.data; - $scope.$apply(); - } - } - }; - $scope.saveSuccess = function (data) { - window.location.href = window.location.href; - }; - $scope.selectData = function () { - if ($scope.selectedList.data.length) { - $scope.viewmodel = $scope.selectedList.data[0]; - } - }; - // $scope.saveSuccessCallback = function () { - // if ($location.path() == "/portal/mix-database-data/create") { - // let backUrl = - // $scope.backUrl || - // `/portal/mix-database-data/details?dataId=${$scope.viewmodel.id}`; - // $rootScope.goToSiteUrl(backUrl); - // } else { - // if ($scope.parentId && $scope.parentType == 'Set') { - // $rootScope.goToSiteUrl(`/portal/mix-database-data/details?dataId=${$scope.parentId}`); - // } else { - // let backUrl = - // $scope.backUrl || - // `/portal/mix-database-data/list?mixDatabaseId=${$scope.viewmodel.mixDatabaseId}&mixDatabaseName=${$scope.viewmodel.mixDatabaseName}&mixDatabaseTitle=${$scope.viewmodel.mixDatabaseName}`; - // $rootScope.goToSiteUrl(backUrl); - // } - // } - // }; - - $scope.preview = function (item) { - item.editUrl = "/portal/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); - }; - $scope.edit = function (data) { - $rootScope.goToPath( - `/portal/mix-database-data/details?dataId=${data.id}&mixDatabaseTitle=${$scope.mixDatabaseTitle}` - ); - }; - $scope.remove = function (data) { - $rootScope.showConfirm( - $scope, - "removeConfirmed", - [data.id], - null, - "Remove", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - - $scope.removeConfirmed = async function (dataId) { - $rootScope.isBusy = true; - var result = await service.delete([dataId]); - if (result.isSucceed) { - if ($scope.removeCallback) { - $rootScope.executeFunctionByName( - "removeCallback", - $scope.removeCallbackArgs, - $scope - ); - } - $scope.getList(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); + $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.getSingleSuccessCallback = async function () { + var getDefaultAttr = await databaseColumnService.getDefault(); + if (getDefaultAttr.isSucceed) { + $scope.defaultAttr = getDefaultAttr.data; + $scope.defaultAttr.options = []; } + $scope.$apply(); }; - $scope.import = async function () { - if ($scope.validateDataFile()) { + $scope.migrate = async function () { + if ($scope.viewmodel.id) { $rootScope.isBusy = true; - var form = document.getElementById("form-portal"); - var result = await service.import( - $scope.mixDatabaseName, - form["import-data-inp"].files[0] - ); + var result = await databaseService.migrate($scope.viewmodel); if (result.isSucceed) { - $rootScope.showMessage("success", "success"); + var migrateData = await databaseDataService.migrate( + $scope.viewmodel.id + ); + $scope.handleResult(migrateData); $rootScope.isBusy = false; - $scope.getList(0); + $scope.$apply(); } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } - } - }; - $scope.validateDataFile = function () { - if (!$scope.importFile.file) { - $rootScope.showMessage("Please choose data file", "danger"); - return false; - } else { - return true; - } - }; - $scope.sendMail = function (data) { - var email = ""; - angular.forEach(data.values, function (e) { - if (e.mixDatabaseColumnName == "email") { - email = e.stringValue; - } - }); - $rootScope.showConfirm( - $scope, - "sendMailConfirmed", - [data], - null, - "Send mail", - "Are you sure to send mail to " + email - ); - }; - $scope.sendMailConfirmed = async function (data) { - $rootScope.isBusy = true; - $rootScope.isBusy = true; - var result = await service.sendMail([data.id]); - if (result.isSucceed) { - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.saveOthers = async function () { - var response = await service.saveList($scope.others); - if (response.isSucceed) { - $scope.getList(); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.selectImportFile = function (files) { - if (files !== undefined && files !== null && files.length > 0) { - const file = files[0]; - $scope.importFile.folder = "imports"; - $scope.importFile.title = $scope.mixDatabaseName; - $scope.importFile.description = $scope.mixDatabaseName + "'s data"; - $scope.importFile.file = file; - - // if (ctrl.auto=='true') { - // ctrl.uploadFile(file); - // } - // else { - // ctrl.getBase64(file); - // } - } - }; - $scope.getList = async function (pageIndex) { - 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 query = {}; - - Object.keys($scope.queries).forEach((e) => { - if ($scope.queries[e]) { - query[e] = $scope.queries[e]; - } - }); - $scope.request.query = JSON.stringify(query); - $rootScope.isBusy = true; - var resp = await service.getList($scope.request); - if (resp && resp.isSucceed) { - $scope.data = resp.data; - $.each($scope.data.items, function (i, data) { - $.each($scope.activeddata, function (i, e) { - if (e.dataId === data.id) { - data.isHidden = true; - } - }); - }); - if ($scope.getListSuccessCallback) { - $scope.getListSuccessCallback(); - } - $("html, body").animate( - { - scrollTop: "0px", - }, - 500 - ); - if (!resp.data || !resp.data.items.length) { - $scope.queries = {}; - } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - if ($scope.getListFailCallback) { - $scope.getListFailCallback(); - } - $scope.queries = {}; - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.export = async function (pageIndex, exportAll) { - 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 query = {}; - if ($routeParams.mixDatabaseId) { - $scope.request.mixDatabaseId = $routeParams.mixDatabaseId; - } - $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; - $scope.request.filterType = $routeParams.filterType || "contain"; - Object.keys($scope.queries).forEach((e) => { - if ($scope.queries[e]) { - query[e] = $scope.queries[e]; - } - }); - $scope.request.query = JSON.stringify(query); - var request = angular.copy($scope.request); - $scope.exportAll = $scope.exportAll; - if (exportAll) { - request.pageSize = 10000; - request.pageIndex = 0; - } - $rootScope.isBusy = true; - var resp = await service.export(request); - if (resp && resp.isSucceed) { - if (resp.data) { - window.top.location = resp.data.webPath; - } else { - $rootScope.showMessage("Nothing to export"); - } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - - $scope.migrate = async function () { - if ($routeParams.mixDatabaseId) { - $rootScope.isBusy = true; - var result = await service.migrate($routeParams.mixDatabaseId); - $scope.handleResult(result); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - }, -]); - -"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.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.getSingleSuccessCallback = async function () { - var getDefaultAttr = await databaseColumnService.getDefault(); - if (getDefaultAttr.isSucceed) { - $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.isSucceed) { - var migrateData = await databaseDataService.migrate( - $scope.viewmodel.id - ); - $scope.handleResult(migrateData); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(["Cannot migrate database"]); + $rootScope.showErrors(["Cannot migrate database"]); $rootScope.isBusy = false; $scope.$apply(); } @@ -2760,16 +2406,14 @@ app.factory("ModuleRestService", [ ]); "use strict"; -app.controller("ModuleDataController", [ +app.controller("MixDatabaseDataController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "ModuleDataRestService", - "ModuleRestService", - "ApiService", - "CommonService", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", function ( $scope, $rootScope, @@ -2777,8 +2421,7 @@ app.controller("ModuleDataController", [ $routeParams, $location, service, - moduleService, - commonService + columnService ) { BaseRestCtrl.call( this, @@ -2789,88 +2432,111 @@ app.controller("ModuleDataController", [ ngAppSettings, service ); + $scope.queries = {}; + $scope.data = {}; + $scope.exportAll = true; + $scope.localizeSettings = $rootScope.globalSettings; // $scope.request.orderBy = "Priority"; // $scope.request.direction = "Asc"; - $scope.cates = ["Site", "System"]; - $scope.others = []; - $scope.localizeSettings = $rootScope.globalSettings; - $scope.moduleId = $routeParams.moduleId; - $scope.backUrl = `/portal/module-data/list/${$scope.moduleId}`; - $scope.module = null; - $scope.dataColumns = []; - $scope.editDataUrl = "/portal/module-data/details/" + $scope.moduleId; - $scope.init = async function () { - $scope.id = $routeParams.id; - if (!$scope.module) { - var getModule = await moduleService.getSingle([$scope.moduleId]); - if (getModule.isSucceed) { - $scope.module = getModule.data; - angular.forEach($scope.module.columns, function (e, i) { - if (e.isDisplay) { - $scope.dataColumns.push({ - title: e.title, - name: e.name, - datatype: e.dataType, - filter: true, - type: 0, // string - ngAppSettings.dataTypes[0] - }); - } - }); + $scope.filterType = "contain"; + $scope.defaultId = "default"; + $scope.importFile = { + file: null, + fullPath: "", + folder: "import", + title: "", + description: "", + }; + $scope.initRouteParams = () => { + $scope.requestKey = `request${$rootScope.generateKeyword( + $location.$$path, + "_" + )}_${$routeParams.mixDatabaseId}`; + $scope.request = $rootScope.getRequest($scope.requestKey); + if ($routeParams.mixDatabaseId) { + $scope.request.mixDatabaseId = $routeParams.mixDatabaseId; + } + $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; + $scope.request.filterType = $routeParams.filterType || "contain"; + $scope.request.compareType = $routeParams.compareType || "or"; + + $scope.mixDatabaseId = $routeParams.mixDatabaseId; + $scope.mixDatabaseName = $routeParams.mixDatabaseName; + $scope.mixDatabaseTitle = $routeParams.mixDatabaseTitle; + $scope.parentId = $routeParams.parentId; + $scope.parentType = $routeParams.parentType; + $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; + $scope.request.isGroup = $routeParams.isGroup || false; + if ($routeParams.backUrl) { + $scope.backUrl = decodeURIComponent($routeParams.backUrl); + } + if ($routeParams.dataId != $scope.defaultId) { + $scope.dataId = $routeParams.dataId; + } + + if ($scope.parentId && $scope.parentType) { + $scope.refDataModel = { + parentId: $scope.parentId, + parentType: $scope.parentType, + }; + } + }; + $scope.init = async function () { + $scope.initRouteParams(); + if ($scope.mixDatabaseName || $scope.mixDatabaseId) { + var getFields = await columnService.initData( + $scope.mixDatabaseName || $scope.mixDatabaseId + ); + if (getFields.isSucceed) { + $scope.columns = getFields.data; $scope.$apply(); } } }; - $scope.getList = async function () { - $rootScope.isBusy = true; - $scope.request.module_id = $scope.moduleId; - var response = await service.getList($scope.request); - if (response.isSucceed) { - $scope.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); + $scope.saveSuccess = function (data) { + if ($scope.backUrl) { + $location.url($scope.backUrl); } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + window.location.href = window.location.href; } }; - - $scope.export = async function () { - $rootScope.isBusy = true; - $scope.request.module_id = $scope.moduleId; - var response = await service.export($scope.request); - if (response.isSucceed) { - window.top.location = response.data.webPath; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + $scope.selectData = function () { + if ($scope.selectedList.data.length) { + $scope.viewmodel = $scope.selectedList.data[0]; } }; + // $scope.saveSuccessCallback = function () { + // if ($location.path() == "/portal/mix-database-data/create") { + // let backUrl = + // $scope.backUrl || + // `/portal/mix-database-data/details?dataId=${$scope.viewmodel.id}`; + // $rootScope.goToSiteUrl(backUrl); + // } else { + // if ($scope.parentId && $scope.parentType == 'Set') { + // $rootScope.goToSiteUrl(`/portal/mix-database-data/details?dataId=${$scope.parentId}`); + // } else { + // let backUrl = + // $scope.backUrl || + // `/portal/mix-database-data/list?mixDatabaseId=${$scope.viewmodel.mixDatabaseId}&mixDatabaseName=${$scope.viewmodel.mixDatabaseName}&mixDatabaseTitle=${$scope.viewmodel.mixDatabaseName}`; + // $rootScope.goToSiteUrl(backUrl); + // } + // } + // }; - $scope.getSingle = async function () { - $rootScope.isBusy = true; - var resp = await service.getSingle($routeParams.id, "portal"); - if (resp && resp.isSucceed) { - $scope.activedModuleData = resp.data; - $rootScope.initEditor(); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } + $scope.preview = function (item) { + item.editUrl = "/portal/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); }; - $scope.remove = function (dataId) { + $scope.edit = function (data) { + $rootScope.goToPath( + `/portal/mix-database-data/details?dataId=${data.id}&mixDatabaseTitle=${$scope.mixDatabaseTitle}` + ); + }; + $scope.remove = function (data) { $rootScope.showConfirm( $scope, "removeConfirmed", - [dataId], + [data.id], null, "Remove", "Deleted data will not able to recover, are you sure you want to delete this item?" @@ -2895,9 +2561,63 @@ app.controller("ModuleDataController", [ $scope.$apply(); } }; - - $scope.removeCallback = function () {}; - + $scope.import = async function () { + if ($scope.validateDataFile()) { + $rootScope.isBusy = true; + var form = document.getElementById("form-portal"); + var result = await service.import( + $scope.mixDatabaseName, + form["import-data-inp"].files[0] + ); + if (result.isSucceed) { + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.getList(0); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + } + }; + $scope.validateDataFile = function () { + if (!$scope.importFile.file) { + $rootScope.showMessage("Please choose data file", "danger"); + return false; + } else { + return true; + } + }; + $scope.sendMail = function (data) { + var email = ""; + angular.forEach(data.values, function (e) { + if (e.mixDatabaseColumnName == "email") { + email = e.stringValue; + } + }); + $rootScope.showConfirm( + $scope, + "sendMailConfirmed", + [data], + null, + "Send mail", + "Are you sure to send mail to " + email + ); + }; + $scope.sendMailConfirmed = async function (data) { + $rootScope.isBusy = true; + $rootScope.isBusy = true; + var result = await service.sendMail([data.id]); + if (result.isSucceed) { + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; $scope.saveOthers = async function () { var response = await service.saveList($scope.others); if (response.isSucceed) { @@ -2909,76 +2629,204 @@ app.controller("ModuleDataController", [ $scope.$apply(); } }; - }, -]); - -"use strict"; -app.factory("ModuleDataRestService", [ - "BaseRestService", - "ApiService", - "CommonService", - function (baseService, apiService, commonService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("module-data/portal"); - // Define more service methods here + $scope.selectImportFile = function (files) { + if (files !== undefined && files !== null && files.length > 0) { + const file = files[0]; + $scope.importFile.folder = "imports"; + $scope.importFile.title = $scope.mixDatabaseName; + $scope.importFile.description = $scope.mixDatabaseName + "'s data"; + $scope.importFile.file = file; - var _initForm = async function (moduleId) { - var url = `${this.prefixUrl}/init-form/${moduleId}`; - var req = { - method: "GET", - url: url, - }; - return await apiService.getRestApiResult(req); + // if (ctrl.auto=='true') { + // ctrl.uploadFile(file); + // } + // else { + // ctrl.getBase64(file); + // } + } }; - serviceFactory.initForm = _initForm; - return serviceFactory; - }, -]); + $scope.getList = async function (pageIndex) { + 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 query = {}; -"use strict"; -app.controller("ModuleGalleryController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "ModuleGalleryService", - "ApiService", - "CommonService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - $location, + Object.keys($scope.queries).forEach((e) => { + if ($scope.queries[e]) { + query[e] = $scope.queries[e]; + } + }); + $scope.request.query = JSON.stringify(query); + $rootScope.isBusy = true; + var resp = await service.getList($scope.request); + if (resp && resp.isSucceed) { + $scope.data = resp.data; + $.each($scope.data.items, function (i, data) { + $.each($scope.activeddata, function (i, e) { + if (e.dataId === data.id) { + data.isHidden = true; + } + }); + }); + if ($scope.getListSuccessCallback) { + $scope.getListSuccessCallback(); + } + $("html, body").animate( + { + scrollTop: "0px", + }, + 500 + ); + if (!resp.data || !resp.data.items.length) { + $scope.queries = {}; + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + if ($scope.getListFailCallback) { + $scope.getListFailCallback(); + } + $scope.queries = {}; + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.export = async function (pageIndex, exportAll) { + 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 query = {}; + if ($routeParams.mixDatabaseId) { + $scope.request.mixDatabaseId = $routeParams.mixDatabaseId; + } + $scope.request.mixDatabaseName = $routeParams.mixDatabaseName; + $scope.request.filterType = $routeParams.filterType || "contain"; + Object.keys($scope.queries).forEach((e) => { + if ($scope.queries[e]) { + query[e] = $scope.queries[e]; + } + }); + $scope.request.query = JSON.stringify(query); + var request = angular.copy($scope.request); + $scope.exportAll = $scope.exportAll; + if (exportAll) { + request.pageSize = 10000; + request.pageIndex = 0; + } + $rootScope.isBusy = true; + var resp = await service.export(request); + if (resp && resp.isSucceed) { + if (resp.data) { + window.top.location = resp.data.webPath; + } else { + $rootScope.showMessage("Nothing to export"); + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.migrate = async function () { + if ($routeParams.mixDatabaseId) { + $rootScope.isBusy = true; + var result = await service.migrate($routeParams.mixDatabaseId); + $scope.handleResult(result); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, +]); + +"use strict"; +app.controller("ModuleDataController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "$location", + "ModuleDataRestService", + "ModuleRestService", + "ApiService", + "CommonService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + $location, service, - apiService, + moduleService, commonService ) { - BaseCtrl.call( + BaseRestCtrl.call( this, $scope, $rootScope, + $location, $routeParams, ngAppSettings, service ); + // $scope.request.orderBy = "Priority"; + // $scope.request.direction = "Asc"; $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $rootScope.globalSettings; - $scope.moduleId = $routeParams.id; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.translate = $rootScope.translate; - $scope.moduleId = $routeParams.id; + $scope.moduleId = $routeParams.moduleId; + $scope.backUrl = `/portal/module-data/list/${$scope.moduleId}`; + $scope.module = null; + $scope.dataColumns = []; + $scope.editDataUrl = "/portal/module-data/details/" + $scope.moduleId; + $scope.init = async function () { + $scope.id = $routeParams.id; + if (!$scope.module) { + var getModule = await moduleService.getSingle([$scope.moduleId]); + if (getModule.isSucceed) { + $scope.module = getModule.data; + angular.forEach($scope.module.columns, function (e, i) { + if (e.isDisplay) { + $scope.dataColumns.push({ + title: e.title, + name: e.name, + datatype: e.dataType, + filter: true, + type: 0, // string - ngAppSettings.dataTypes[0] + }); + } + }); + $scope.$apply(); + } + } + }; $scope.getList = async function () { $rootScope.isBusy = true; - var id = $routeParams.id; - $scope.moduleId = $routeParams.id; - $scope.request.query = "&module_id=" + id; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || - $scope.request.direction !== "0"; + $scope.request.module_id = $scope.moduleId; var response = await service.getList($scope.request); if (response.isSucceed) { $scope.data = response.data; @@ -2990,20 +2838,52 @@ app.controller("ModuleGalleryController", [ $scope.$apply(); } }; - $scope.remove = function (moduleId, postId) { + + $scope.export = async function () { + $rootScope.isBusy = true; + $scope.request.module_id = $scope.moduleId; + var response = await service.export($scope.request); + if (response.isSucceed) { + window.top.location = response.data.webPath; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.getSingle = async function () { + $rootScope.isBusy = true; + var resp = await service.getSingle($routeParams.id, "portal"); + if (resp && resp.isSucceed) { + $scope.activedModuleData = resp.data; + $rootScope.initEditor(); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.remove = function (dataId) { $rootScope.showConfirm( $scope, "removeConfirmed", - [moduleId, postId], + [dataId], null, "Remove", "Deleted data will not able to recover, are you sure you want to delete this item?" ); }; - $scope.removeConfirmed = async function (moduleId, postId) { + $scope.removeConfirmed = async function (dataId) { $rootScope.isBusy = true; - var result = await service.delete(moduleId, postId); + var result = await service.delete([dataId]); if (result.isSucceed) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -3033,69 +2913,40 @@ app.controller("ModuleGalleryController", [ $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.isSucceed) { - $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("ModuleGalleryService", [ - "$rootScope", +app.factory("ModuleDataRestService", [ + "BaseRestService", "ApiService", "CommonService", - "BaseService", - function ($rootScope, apiService, commonService, baseService) { + function (baseService, apiService, commonService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("module-post"); - var _delete = async function (moduleId, postId) { - var url = this.prefixUrl + "/delete/" + moduleId + "/" + postId; + serviceFactory.init("module-data/portal"); + // Define more service methods here + + var _initForm = async function (moduleId) { + var url = `${this.prefixUrl}/init-form/${moduleId}`; var req = { method: "GET", url: url, }; - return await apiService.getApiResult(req); - }; - var _updateInfos = async function (modules) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(modules), - }; - return await apiService.getApiResult(req); + return await apiService.getRestApiResult(req); }; - serviceFactory.delete = _delete; - serviceFactory.updateInfos = _updateInfos; + serviceFactory.initForm = _initForm; return serviceFactory; }, ]); "use strict"; -app.controller("ModulePostController", [ +app.controller("ModuleGalleryController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "ModulePostRestService", + "ModuleGalleryService", "ApiService", "CommonService", function ( @@ -3105,6 +2956,7 @@ app.controller("ModulePostController", [ $routeParams, $location, service, + apiService, commonService ) { BaseCtrl.call( @@ -3118,23 +2970,13 @@ app.controller("ModulePostController", [ $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $rootScope.globalSettings; + $scope.moduleId = $routeParams.id; $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; $scope.translate = $rootScope.translate; - $scope.moduleIds = $routeParams.moduleIds || $routeParams.id; - $scope.pageIds = $routeParams.page_ids || ""; - $scope.type = $routeParams.type || ""; - $scope.template = $routeParams.template || ""; - - $scope.init = function () { - $scope.createUrl = `/portal/post/create?page_ids=${$scope.pageIds}&module_ids=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; - $scope.getList(); - }; - $scope.getList = async function (pageIndex) { + $scope.moduleId = $routeParams.id; + $scope.getList = async function () { $rootScope.isBusy = true; - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } var id = $routeParams.id; $scope.moduleId = $routeParams.id; $scope.request.query = "&module_id=" + id; @@ -3152,10 +2994,6 @@ app.controller("ModulePostController", [ $scope.$apply(); } }; - $scope.preview = function (item) { - item.editUrl = "/portal/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); - }; $scope.remove = function (moduleId, postId) { $rootScope.showConfirm( $scope, @@ -3224,7 +3062,7 @@ app.controller("ModulePostController", [ ]); "use strict"; -app.factory("ModulePostRestService", [ +app.factory("ModuleGalleryService", [ "$rootScope", "ApiService", "CommonService", @@ -3474,14 +3312,13 @@ app.factory("OrderServices", [ ]); "use strict"; -app.controller("PageGalleryController", [ +app.controller("ModulePostController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "PageGalleryService", - "PostRestService", + "ModulePostRestService", "ApiService", "CommonService", function ( @@ -3491,8 +3328,6 @@ app.controller("PageGalleryController", [ $routeParams, $location, service, - postService, - apiService, commonService ) { BaseCtrl.call( @@ -3506,17 +3341,30 @@ app.controller("PageGalleryController", [ $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $rootScope.globalSettings; - $scope.pageId = $routeParams.id; $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.getList = async function () { + $scope.translate = $rootScope.translate; + $scope.moduleIds = $routeParams.moduleIds || $routeParams.id; + $scope.pageIds = $routeParams.page_ids || ""; + $scope.type = $routeParams.type || ""; + $scope.template = $routeParams.template || ""; + + $scope.init = function () { + $scope.createUrl = `/portal/post/create?page_ids=${$scope.pageIds}&module_ids=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; + $scope.getList(); + }; + $scope.getList = async function (pageIndex) { $rootScope.isBusy = true; + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } var id = $routeParams.id; - $scope.request.query = "&page_id=" + id; - var response = await service.getList($scope.request); + $scope.moduleId = $routeParams.id; + $scope.request.query = "&module_id=" + id; $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; + var response = await service.getList($scope.request); if (response.isSucceed) { $scope.data = response.data; $rootScope.isBusy = false; @@ -3527,20 +3375,24 @@ app.controller("PageGalleryController", [ $scope.$apply(); } }; - $scope.remove = function (pageId, postId) { + $scope.preview = function (item) { + item.editUrl = "/portal/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); + }; + $scope.remove = function (moduleId, postId) { $rootScope.showConfirm( $scope, "removeConfirmed", - [pageId, postId], + [moduleId, 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) { + $scope.removeConfirmed = async function (moduleId, postId) { $rootScope.isBusy = true; - var result = await service.delete(pageId, postId); + var result = await service.delete(moduleId, postId); if (result.isSucceed) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -3557,6 +3409,8 @@ app.controller("PageGalleryController", [ } }; + $scope.removeCallback = function () {}; + $scope.saveOthers = async function () { var response = await service.saveList($scope.others); if (response.isSucceed) { @@ -3593,27 +3447,27 @@ app.controller("PageGalleryController", [ ]); "use strict"; -app.factory("PageGalleryService", [ +app.factory("ModulePostRestService", [ "$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; + serviceFactory.init("module-post"); + var _delete = async function (moduleId, postId) { + var url = this.prefixUrl + "/delete/" + moduleId + "/" + postId; var req = { method: "GET", url: url, }; return await apiService.getApiResult(req); }; - var _updateInfos = async function (pages) { + var _updateInfos = async function (modules) { var req = { method: "POST", url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), + data: JSON.stringify(modules), }; return await apiService.getApiResult(req); }; @@ -3624,13 +3478,13 @@ app.factory("PageGalleryService", [ ]); "use strict"; -app.controller("PagePageController", [ +app.controller("PageGalleryController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "PagePostRestService", + "PageGalleryService", "PostRestService", "ApiService", "CommonService", @@ -3743,14 +3597,14 @@ app.controller("PagePageController", [ ]); "use strict"; -app.factory("PagePageRestService", [ +app.factory("PageGalleryService", [ "$rootScope", "ApiService", "CommonService", "BaseService", function ($rootScope, apiService, commonService, baseService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("page-page"); + serviceFactory.init("page-post"); var _delete = async function (pageId, postId) { var url = this.prefixUrl + "/delete/" + pageId + "/" + postId; var req = { @@ -3774,51 +3628,62 @@ app.factory("PagePageRestService", [ ]); "use strict"; -app.controller("PagePositionController", [ +app.controller("PageController", [ "$scope", "$rootScope", "ngAppSettings", - "$routeParams", "$location", - "PagePositionService", - "PostRestService", - "ApiService", - "CommonService", + "$routeParams", + "PageRestService", + "PagePostRestService", + "PagePageRestService", + "UrlAliasService", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", function ( $scope, $rootScope, ngAppSettings, - $routeParams, $location, + $routeParams, service, - postService, - apiService, - commonService + pagePostRestService, + pagePageRestService, + urlAliasService, + dataService, + columnService ) { - BaseCtrl.call( + BaseRestCtrl.call( this, $scope, $rootScope, + $location, $routeParams, ngAppSettings, service ); - $scope.cates = ["Site", "System"]; - $scope.others = []; - $scope.localizeSettings = $rootScope.globalSettings; - $scope.pageId = $routeParams.id; + $scope.viewmodelType = "page"; + $scope.request.query = "level=0"; + $scope.pageType = ""; + $scope.pageTypes = $rootScope.globalSettings.pageTypes; + $scope.selectedCategories = []; + $scope.selectedTags = []; + $scope.pageData = { + posts: [], + products: [], + data: [], + }; + $scope.postRequest = angular.copy(ngAppSettings.request); $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.getList = async function () { + $scope.loadPosts = 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"; + $scope.postRequest.query += "&page_id=" + id; + var response = await pagePostRestService.getList($scope.postRequest); + if (response.isSucceed) { - $scope.data = response.data; + $scope.pageData.posts = response.data; $rootScope.isBusy = false; $scope.$apply(); } else { @@ -3827,50 +3692,35 @@ app.controller("PagePositionController", [ $scope.$apply(); } }; - $scope.preview = function (item) { - item.editUrl = "/portal/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); + $scope.getSingleSuccessCallback = function () { + $scope.loadAdditionalData(); + if ($routeParams.template) { + $scope.viewmodel.view = $rootScope.findObjectByKey( + $scope.viewmodel.templates, + "fileName", + $routeParams.template + ); + } }; - $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.getListSuccessCallback = function () { + $scope.canDrag = + $scope.request.orderBy !== "Priority" || + $scope.request.direction !== "0"; }; - - $scope.removeConfirmed = async function (pageId, postId) { - $rootScope.isBusy = true; - var result = await service.delete(pageId, postId); - if (result.isSucceed) { - if ($scope.removeCallback) { - $rootScope.executeFunctionByName( - "removeCallback", - $scope.removeCallbackArgs, - $scope - ); - } - $scope.getList(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; + $scope.loadAdditionalData = async function () { + const obj = { + parentType: "Page", + parentId: $scope.viewmodel.id, + databaseName: "sys_additional_column_page", + }; + const getData = await dataService.getAdditionalData(obj); + if (getData.isSucceed) { + $scope.additionalData = getData.data; $scope.$apply(); } }; - - $scope.saveOthers = async function () { - var response = await service.saveList($scope.others); - if (response.isSucceed) { - $scope.getList(); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } + $scope.showChilds = function (id) { + $("#childs-" + id).toggleClass("collapse"); }; $scope.updateInfos = async function (index) { $scope.data.items.splice(index, 1); @@ -3893,59 +3743,170 @@ app.controller("PagePositionController", [ $scope.$apply(); } }; - }, -]); - -"use strict"; -app.factory("PagePositionService", [ - "$rootScope", - "ApiService", - "CommonService", - "BaseService", - function ($rootScope, apiService, commonService, baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("page-position"); - var _delete = async function (pageId, positionId) { - var url = this.prefixUrl + "/delete/" + pageId + "/" + positionId; - var req = { - method: "GET", - url: url, - }; - return await apiService.getApiResult(req); + $scope.selPageType = function () { + $scope.request.query = "level=0&pageType=" + $scope.pageType; + $scope.getList(); }; - var _updateInfos = async function (pages) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), - }; - return await apiService.getApiResult(req); + $scope.goUp = async function (items, index) { + items[index].priority -= 1; + items[index - 1].priority += 1; }; - serviceFactory.delete = _delete; - serviceFactory.updateInfos = _updateInfos; - return serviceFactory; - }, -]); -"use strict"; -app.controller("PagePostController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$location", - "PagePostRestService", - "PostRestService", - "ApiService", - "CommonService", - function ( - $scope, + $scope.goDown = async function (items, index) { + items[index].priority += 1; + items[index - 1].priority -= 1; + }; + + $scope.updatePagePage = async function (items) { + $rootScope.isBusy = true; + var resp = await pagePageRestService.updateInfos(items); + if (resp && resp.isSucceed) { + $scope.activedPage = resp.data; + $rootScope.showMessage("success", "success"); + $scope.getList(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.saveSuccessCallback = async function () { + if ($scope.additionalData) { + $scope.additionalData.isClone = $scope.viewmodel.isClone; + $scope.additionalData.cultures = $scope.viewmodel.cultures; + $scope.additionalData.parentId = $scope.viewmodel.id; + $scope.additionalData.parentType = "Page"; + let result = await dataService.save($scope.additionalData); + if (!result.isSucceed) { + $rootScope.showErrors(result.errors); + } else { + $scope.additionalData = result.data; + $scope.saveColumns(); + } + } + $rootScope.isBusy = false; + $scope.$apply(); + }; + + $scope.saveColumns = async function () { + let result = await columnService.saveMany($scope.additionalData.columns); + if (result.isSucceed) { + $rootScope.showMessage("success", "success"); + } + }; + + $scope.validate = async function () { + // Add default alias if create new page + if (!$scope.viewmodel.id && !$scope.viewmodel.urlAliases.length) { + // Ex: en-us/page-seo-name + // await $scope.addAlias($scope.viewmodel.specificulture + '/' + $scope.viewmodel.seoName); + return true; + } else { + return true; + } + }; + $scope.addAlias = async function (alias) { + var getAlias = await urlAliasService.getSingle(); + if (getAlias.isSucceed) { + if (alias) { + getAlias.data.alias = alias; + } + $scope.viewmodel.urlAliases.push(getAlias.data); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(getAlias.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.updateSysCategories = function (data) { + // Loop selected categories + angular.forEach($scope.selectedCategories, function (e) { + // add if not exist in sysCategories + var current = $rootScope.findObjectByKey( + $scope.viewmodel.sysCategories, + "id", + e.id + ); + if (!current) { + $scope.viewmodel.sysCategories.push({ + id: e.id, + parentId: $scope.viewmodel.id, + mixDatabaseName: "sys_category", + }); + } + }); + }; + $scope.updateSysTags = function (data) { + // Loop selected categories + angular.forEach($scope.selectedTags, function (e) { + // add if not exist in sysCategories + var current = $rootScope.findObjectByKey( + $scope.viewmodel.sysTags, + "id", + e.id + ); + if (!current) { + $scope.viewmodel.sysCategories.push({ + id: e.id, + parentId: $scope.viewmodel.id, + mixDatabaseName: "sys_tag", + }); + } + }); + }; + $scope.removeAliasCallback = async function (index) { + $scope.viewmodel.urlAliases.splice(index, 1); + $scope.$apply(); + }; + }, +]); + +"use strict"; +app.factory("PageRestService", [ + "$rootScope", + "ApiService", + "CommonService", + "BaseRestService", + function ($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("page/portal"); + var _updateInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-infos", + data: JSON.stringify(pages), + }; + return await apiService.getApiResult(req); + }; + serviceFactory.updateInfos = _updateInfos; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("PagePageController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "$location", + "PagePostRestService", + "PostRestService", + "ApiService", + "CommonService", + function ( + $scope, $rootScope, ngAppSettings, $routeParams, $location, service, postService, + apiService, commonService ) { BaseCtrl.call( @@ -3959,35 +3920,17 @@ app.controller("PagePostController", [ $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $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" - ? "/portal/post/create-gallery" - : `/portal/post/create?page_ids=${$scope.pageIds}&module_ids=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; - $scope.updateUrl = - $routeParams.post_type === "gallery" - ? "/portal/post/gallery-details" - : "/portal/post/details"; - }; - $scope.getList = async function (pageIndex) { - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; - } + $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 === "Asc"; + $scope.request.orderBy !== "Priority" || + $scope.request.direction !== "0"; if (response.isSucceed) { $scope.data = response.data; $rootScope.isBusy = false; @@ -3998,10 +3941,6 @@ app.controller("PagePostController", [ $scope.$apply(); } }; - $scope.preview = function (item) { - item.editUrl = "/portal/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); - }; $scope.remove = function (pageId, postId) { $rootScope.showConfirm( $scope, @@ -4012,13 +3951,10 @@ app.controller("PagePostController", [ "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) { + $scope.removeConfirmed = async function (pageId, postId) { $rootScope.isBusy = true; - var result = await service.delete(id); + var result = await service.delete(pageId, postId); if (result.isSucceed) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -4071,92 +4007,82 @@ app.controller("PagePostController", [ ]); "use strict"; -app.factory("PagePostRestService", [ - "$rootScope", - "ApiService", - "CommonService", - "BaseService", - function($rootScope, apiService, commonService, baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("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; - }, +app.factory("PagePageRestService", [ + "$rootScope", + "ApiService", + "CommonService", + "BaseService", + function ($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("page-page"); + var _delete = async function (pageId, postId) { + var url = this.prefixUrl + "/delete/" + pageId + "/" + postId; + 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("PageController", [ +app.controller("PagePositionController", [ "$scope", "$rootScope", "ngAppSettings", - "$location", "$routeParams", - "PageRestService", - "PagePostRestService", - "PagePageRestService", - "UrlAliasService", - "RestMixDatabaseDataPortalService", - "RestMixDatabaseColumnPortalService", + "$location", + "PagePositionService", + "PostRestService", + "ApiService", + "CommonService", function ( $scope, $rootScope, ngAppSettings, - $location, $routeParams, + $location, service, - pagePostRestService, - pagePageRestService, - urlAliasService, - dataService, - columnService + postService, + apiService, + commonService ) { - BaseRestCtrl.call( + BaseCtrl.call( this, $scope, $rootScope, - $location, $routeParams, ngAppSettings, service ); - $scope.viewmodelType = "page"; - $scope.request.query = "level=0"; - $scope.pageType = ""; - $scope.pageTypes = $rootScope.globalSettings.pageTypes; - $scope.selectedCategories = []; - $scope.selectedTags = []; - $scope.pageData = { - posts: [], - products: [], - data: [], - }; - $scope.postRequest = angular.copy(ngAppSettings.request); + $scope.cates = ["Site", "System"]; + $scope.others = []; + $scope.localizeSettings = $rootScope.globalSettings; + $scope.pageId = $routeParams.id; $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.loadPosts = async function () { + $scope.getList = async function () { $rootScope.isBusy = true; var id = $routeParams.id; - $scope.postRequest.query += "&page_id=" + id; - var response = await pagePostRestService.getList($scope.postRequest); - + $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.isSucceed) { - $scope.pageData.posts = response.data; + $scope.data = response.data; $rootScope.isBusy = false; $scope.$apply(); } else { @@ -4165,35 +4091,50 @@ app.controller("PageController", [ $scope.$apply(); } }; - $scope.getSingleSuccessCallback = function () { - $scope.loadAdditionalData(); - if ($routeParams.template) { - $scope.viewmodel.view = $rootScope.findObjectByKey( - $scope.viewmodel.templates, - "fileName", - $routeParams.template - ); - } + $scope.preview = function (item) { + item.editUrl = "/portal/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); }; - $scope.getListSuccessCallback = function () { - $scope.canDrag = - $scope.request.orderBy !== "Priority" || - $scope.request.direction !== "0"; + $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.loadAdditionalData = async function () { - const obj = { - parentType: "Page", - parentId: $scope.viewmodel.id, - databaseName: "sys_additional_column_page", - }; - const getData = await dataService.getAdditionalData(obj); - if (getData.isSucceed) { - $scope.additionalData = getData.data; + + $scope.removeConfirmed = async function (pageId, postId) { + $rootScope.isBusy = true; + var result = await service.delete(pageId, postId); + if (result.isSucceed) { + if ($scope.removeCallback) { + $rootScope.executeFunctionByName( + "removeCallback", + $scope.removeCallbackArgs, + $scope + ); + } + $scope.getList(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.showChilds = function (id) { - $("#childs-" + id).toggleClass("collapse"); + + $scope.saveOthers = async function () { + var response = await service.saveList($scope.others); + if (response.isSucceed) { + $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); @@ -4216,137 +4157,26 @@ app.controller("PageController", [ $scope.$apply(); } }; - $scope.selPageType = function () { - $scope.request.query = "level=0&pageType=" + $scope.pageType; - $scope.getList(); - }; - $scope.goUp = async function (items, index) { - items[index].priority -= 1; - items[index - 1].priority += 1; - }; - - $scope.goDown = async function (items, index) { - items[index].priority += 1; - items[index - 1].priority -= 1; - }; - - $scope.updatePagePage = async function (items) { - $rootScope.isBusy = true; - var resp = await pagePageRestService.updateInfos(items); - if (resp && resp.isSucceed) { - $scope.activedPage = resp.data; - $rootScope.showMessage("success", "success"); - $scope.getList(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.saveSuccessCallback = async function () { - if ($scope.additionalData) { - $scope.additionalData.isClone = $scope.viewmodel.isClone; - $scope.additionalData.cultures = $scope.viewmodel.cultures; - $scope.additionalData.parentId = $scope.viewmodel.id; - $scope.additionalData.parentType = "Page"; - let result = await dataService.save($scope.additionalData); - if (!result.isSucceed) { - $rootScope.showErrors(result.errors); - } else { - $scope.additionalData = result.data; - $scope.saveColumns(); - } - } - $rootScope.isBusy = false; - $scope.$apply(); - }; - - $scope.saveColumns = async function () { - let result = await columnService.saveMany($scope.additionalData.columns); - if (result.isSucceed) { - $rootScope.showMessage("success", "success"); - } - }; - - $scope.validate = async function () { - // Add default alias if create new page - if (!$scope.viewmodel.id && !$scope.viewmodel.urlAliases.length) { - // Ex: en-us/page-seo-name - // await $scope.addAlias($scope.viewmodel.specificulture + '/' + $scope.viewmodel.seoName); - return true; - } else { - return true; - } - }; - $scope.addAlias = async function (alias) { - var getAlias = await urlAliasService.getSingle(); - if (getAlias.isSucceed) { - if (alias) { - getAlias.data.alias = alias; - } - $scope.viewmodel.urlAliases.push(getAlias.data); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(getAlias.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - $scope.updateSysCategories = function (data) { - // Loop selected categories - angular.forEach($scope.selectedCategories, function (e) { - // add if not exist in sysCategories - var current = $rootScope.findObjectByKey( - $scope.viewmodel.sysCategories, - "id", - e.id - ); - if (!current) { - $scope.viewmodel.sysCategories.push({ - id: e.id, - parentId: $scope.viewmodel.id, - mixDatabaseName: "sys_category", - }); - } - }); - }; - $scope.updateSysTags = function (data) { - // Loop selected categories - angular.forEach($scope.selectedTags, function (e) { - // add if not exist in sysCategories - var current = $rootScope.findObjectByKey( - $scope.viewmodel.sysTags, - "id", - e.id - ); - if (!current) { - $scope.viewmodel.sysCategories.push({ - id: e.id, - parentId: $scope.viewmodel.id, - mixDatabaseName: "sys_tag", - }); - } - }); - }; - $scope.removeAliasCallback = async function (index) { - $scope.viewmodel.urlAliases.splice(index, 1); - $scope.$apply(); - }; }, ]); "use strict"; -app.factory("PageRestService", [ +app.factory("PagePositionService", [ "$rootScope", "ApiService", "CommonService", - "BaseRestService", + "BaseService", function ($rootScope, apiService, commonService, baseService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("page/portal"); + serviceFactory.init("page-position"); + var _delete = async function (pageId, positionId) { + var url = this.prefixUrl + "/delete/" + pageId + "/" + positionId; + var req = { + method: "GET", + url: url, + }; + return await apiService.getApiResult(req); + }; var _updateInfos = async function (pages) { var req = { method: "POST", @@ -4355,34 +4185,33 @@ app.factory("PageRestService", [ }; return await apiService.getApiResult(req); }; + serviceFactory.delete = _delete; serviceFactory.updateInfos = _updateInfos; return serviceFactory; }, ]); "use strict"; -app.controller("PostController", [ +app.controller("PermissionController", [ "$scope", "$rootScope", - "$location", - "$filter", "ngAppSettings", "$routeParams", - "PostRestService", - "UrlAliasService", - "RestMixDatabaseDataPortalService", - "RestMixDatabaseColumnPortalService", + "$location", + "ApiService", + "CommonService", + "PermissionService", + "RestPortalPageNavigationService", function ( $scope, $rootScope, - $location, - $filter, ngAppSettings, $routeParams, + $location, + apiService, + commonService, service, - urlAliasService, - dataService, - columnService + navService ) { BaseRestCtrl.call( this, @@ -4393,96 +4222,21 @@ app.controller("PostController", [ ngAppSettings, service ); - $scope.viewmodelType = "post"; - $scope.additionalData = null; - $scope.createUrl = "/portal/post/create?"; - $scope.selectedCategories = []; - $scope.selectedTags = []; - $scope.postType = { - databaseName: "", - title: "All", + $scope.request.level = 0; + $scope.miOptions = ngAppSettings.miIcons; + $scope.initDialog = function () { + $("#dlg-permission").on("shown.bs.modal", function () { + $scope.initCurrentPath(); + }); }; - $scope.cateRequest = angular.copy(ngAppSettings.request); - $scope.postTypeRequest = angular.copy(ngAppSettings.request); - $scope.postTypeRequest.mixDatabaseName = "post_type"; - $scope.postTypeRequest.orderBy = "Priority"; - $scope.postTypeRequest.direction = "Asc"; - $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.postType = $routeParams.type; - } - if ($routeParams.page_ids) { - $scope.createUrl = `${$scope.createUrl}&page_ids=${$routeParams.page_ids}`; - } - $scope.pageName = "postList"; - await $scope.loadPostTypes(); - await $scope.loadCategories(); - $scope.getList(); - }; - $scope.loadCategories = async function () { - $scope.cateRequest.mixDatabaseName = "sys_category"; - var response = await dataService.getList($scope.cateRequest); - if (response.isSucceed) { - $scope.categories = response.data; - $scope.isBusy = false; - $scope.$apply(); - } - }; - $scope.loadPostTypes = async function () { - let getTypes = await dataService.getList($scope.postTypeRequest); - if (getTypes.isSucceed) { - $scope.postTypes = getTypes.data.items.map((m) => m.obj); - $scope.postTypes.splice( - 0, - 0, - { - databaseName: "", - title: "All", - id: 0, - }, - { - databaseName: "sys_additional_column_post", - title: "Default", - id: 1, - } - ); - if ($scope.request.postType) { - $scope.postType = $rootScope.findObjectByKey( - $scope.postTypes, - "databaseName", - $scope.request.postType - ); - } - $scope.request.postType = $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.isSucceed) { + $scope.initCurrentPath = async function () { + var resp = await service.getDefault(); + if (resp && resp.isSucceed) { $scope.viewmodel = resp.data; - if ($scope.getSingleSuccessCallback) { - $scope.getSingleSuccessCallback(); - } - - // $scope.viewmodel.createdDateTime = Date.now(); - $scope.viewmodel.createdBy = $rootScope.authentication.username; - + $scope.viewmodel.url = $location.url(); $rootScope.isBusy = false; - $scope.$apply(); + $scope.$applyAsync(); } else { if (resp) { $rootScope.showErrors(resp.errors); @@ -4494,319 +4248,115 @@ app.controller("PostController", [ $scope.$apply(); } }; - $scope.preview = function (item) { - item.editUrl = "/portal/post/details/" + item.id; - $rootScope.preview("post", item, item.title, "modal-lg"); + $scope.saveSuccessCallback = function () { + $scope.getSingle(); }; - $scope.onSelectType = function () { - if ($scope.viewmodel) { - $scope.viewmodel.type = $scope.postType.databaseName; - $scope.loadAdditionalData(); - } - $scope.request.postType = $scope.postType.databaseName; - $scope.createUrl = `/portal/post/create?type=${$scope.request.postType}`; - if ($routeParams.template) { - $scope.createUrl += `&template=${$routeParams.template}`; - } - if ( - $scope.postType.databaseName && - (!$scope.viewmodel || !$scope.viewmodel.id) - ) { - $scope.getDefault($scope.request.postType); - } - if ($scope.pageName == "postList") { - $scope.getList(); - } + + $scope.dragStart = function (index) { + $scope.minPriority = $scope.data.items[0].priority; + $scope.dragStartIndex = index; }; - $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(); + $scope.updateOrders = function (index) { + if (index > $scope.dragStartIndex) { + $scope.data.items.splice($scope.dragStartIndex, 1); + } else { + $scope.data.items.splice($scope.dragStartIndex + 1, 1); } - var resp = await service.getList($scope.request); - if (resp && resp.isSucceed) { - let result = []; - 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); - } + angular.forEach($scope.data.items, function (e, i) { + e.priority = $scope.minPriority + i; + service.saveFields(e.id, { priority: e.priority }).then((resp) => { + $rootScope.isBusy = false; + $scope.$apply(); }); - resp.data.items = result; + }); + }; + + $scope.updateChildInfos = async function (items) { + $rootScope.isBusy = true; + var resp = await service.updateChildInfos(items); + if (resp && resp.isSucceed) { + $scope.activedPage = resp.data; + $rootScope.showMessage("success", "success"); $rootScope.isBusy = false; $scope.$apply(); - return resp.data; } else { - $rootScope.showErrors(getData.errors); + if (resp) { + $rootScope.showErrors(resp.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.additionalData.isClone = $scope.viewmodel.isClone; - $scope.additionalData.cultures = $scope.viewmodel.cultures; - $scope.additionalData.parentId = $scope.viewmodel.id; - $scope.additionalData.parentType = "Post"; - let result = await dataService.save($scope.additionalData); - if (!result.isSucceed) { - $rootScope.showErrors(result.errors); - } else { - $scope.additionalData = result.data; - $scope.saveColumns(); - } - } - $rootScope.isBusy = false; - $scope.$apply(); + $("#dlg-favorite").on("show.bs.modal", function (event) { + $scope.initCurrentPath(); + }); + }, +]); + +"use strict"; +app.factory("PermissionService", [ + "BaseRestService", + "ApiService", + "CommonService", + function (baseService, apiService, commonService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("permission", true); + var _updateInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-infos", + data: JSON.stringify(pages), + }; + return await apiService.getApiResult(req); }; - $scope.saveColumns = async function () { - let result = await columnService.saveMany($scope.additionalData.columns); - if (result.isSucceed) { - $rootScope.showMessage("success", "success"); - } + var _updateChildInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-child-infos", + data: JSON.stringify(pages), + }; + return await apiService.getApiResult(req); }; - $scope.getSingleSuccessCallback = async function () { - $scope.defaultThumbnailImgWidth = - ngAppSettings.localizeSettings.DefaultThumbnailImgWidth; - $scope.defaultThumbnailImgHeight = - ngAppSettings.localizeSettings.DefaultThumbnailImgHeight; - $scope.defaultFeatureImgWidth = - ngAppSettings.localizeSettings.DefaultFeatureImgWidth; - $scope.defaultFeatureImgHeight = - ngAppSettings.localizeSettings.DefaultFeatureImgHeight; - - $scope.request.postType = $scope.viewmodel.type; - var moduleIds = $routeParams.module_ids; - var pageIds = $routeParams.page_ids; - $scope.postType = $rootScope.findObjectByKey( - $scope.postTypes, - "databaseName", - $scope.request.postType - ); - await $scope.loadCategories(); - $scope.loadAdditionalData(); - if (moduleIds) { - for (var moduleId of moduleIds.split(",")) { - var moduleNav = $rootScope.findObjectByKey( - $scope.viewmodel.modules, - "moduleId", - moduleId - ); - 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; - } - } - } - if ($scope.viewmodel.sysCategories) { - angular.forEach($scope.viewmodel.sysCategories, function (e) { - e.attributeData.obj.isActived = true; - $scope.selectedCategories.push(e.attributeData.obj); - }); - } - - if ($scope.viewmodel.sysTags) { - angular.forEach($scope.viewmodel.sysTags, function (e) { - e.attributeData.obj.isActived = true; - $scope.selectedCategories.push(e.attributeData.obj); - }); - } - if ($routeParams.template) { - $scope.viewmodel.view = $rootScope.findObjectByKey( - $scope.viewmodel.templates, - "fileName", - $routeParams.template - ); - } - }; - $scope.loadAdditionalData = async function () { - const obj = { - parentType: "Post", - parentId: $scope.viewmodel.id, - databaseName: $scope.viewmodel.type || "", - }; - const getData = await dataService.getAdditionalData(obj); - if (getData.isSucceed) { - $scope.additionalData = getData.data; - $scope.$apply(); - } - }; - $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; - } - } - }; - $scope.addAlias = async function () { - var getAlias = await urlAliasService.getSingle(); - if (getAlias.isSucceed) { - $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.updateSysCategories = function (data) { - // Loop selected categories - angular.forEach($scope.selectedCategories, function (e) { - // add if not exist in sysCategories - var current = $rootScope.findObjectByKey( - $scope.viewmodel.sysCategories, - "id", - e.id - ); - if (!current) { - $scope.viewmodel.sysCategories.push({ - id: e.id, - parentId: $scope.viewmodel.id, - mixDatabaseName: "sys_category", - }); - } - }); - }; - $scope.updateSysTags = function (data) { - // Loop selected categories - angular.forEach($scope.selectedTags, function (e) { - // add if not exist in sysCategories - var current = $rootScope.findObjectByKey( - $scope.viewmodel.sysTags, - "id", - e.id - ); - if (!current) { - $scope.viewmodel.sysCategories.push({ - id: e.id, - parentId: $scope.viewmodel.id, - mixDatabaseName: "sys_tag", - }); - } - }); - }; - $scope.validate = function () { - angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { - if (nav.isActived) { - $rootScope.encryptMixDatabase( - nav.mixDatabase.attributes, - nav.mixDatabase.postData.items - ); - } - }); - return true; - }; + serviceFactory.updateInfos = _updateInfos; + serviceFactory.updateChildInfos = _updateChildInfos; + return serviceFactory; }, ]); "use strict"; -app.factory("PostRestService", [ +app.factory("RestPortalPageNavigationService", [ "BaseRestService", - function (baseService) { + "ApiService", + "CommonService", + function (baseService, apiService, commonService) { var serviceFactory = Object.create(baseService); - serviceFactory.init("post/portal"); - // Define more service methods here + serviceFactory.init("portal-page-navigation", true); + return serviceFactory; }, ]); "use strict"; -app.controller("PermissionController", [ +app.controller("RoleController", [ "$scope", "$rootScope", - "ngAppSettings", - "$routeParams", "$location", - "ApiService", - "CommonService", - "PermissionService", - "RestPortalPageNavigationService", + "$routeParams", + "ngAppSettings", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", + "RoleService", function ( $scope, $rootScope, - ngAppSettings, - $routeParams, $location, - apiService, - commonService, - service, - navService + $routeParams, + ngAppSettings, + dataService, + columnService, + service ) { BaseRestCtrl.call( this, @@ -4817,172 +4367,27 @@ app.controller("PermissionController", [ ngAppSettings, service ); - $scope.request.level = 0; - $scope.miOptions = ngAppSettings.miIcons; - $scope.initDialog = function () { - $("#dlg-permission").on("shown.bs.modal", function () { - $scope.initCurrentPath(); - }); + $scope.role = { name: "" }; + $scope.initPermissions = async function () { + let backUrl = "/portal/role/list"; + $scope.createUrl = `/portal/mix-database-data/create?mixDatabaseName=sys_permission&dataId=default&parentId=${$scope.viewmodel.id}&parentType=Role&backUrl=${backUrl}`; + $scope.updateUrl = "/portal/mix-database-data/details"; }; - $scope.initCurrentPath = async function () { - var resp = await service.getDefault(); - if (resp && resp.isSucceed) { - $scope.viewmodel = resp.data; - $scope.viewmodel.url = $location.url(); - $rootScope.isBusy = false; - $scope.$applyAsync(); + $scope.createRole = async function () { + $rootScope.isBusy = true; + var result = await service.createRole($scope.role.name); + if (result.isSucceed) { + $scope.role.name = ""; + $scope.getList(); } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - if ($scope.getSingleFailCallback) { - $scope.getSingleFailCallback(); - } + $rootScope.showErrors(result.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.saveSuccessCallback = function () { - $scope.getSingle(); - }; - - $scope.dragStart = function (index) { - $scope.minPriority = $scope.data.items[0].priority; - $scope.dragStartIndex = index; - }; - $scope.updateOrders = function (index) { - if (index > $scope.dragStartIndex) { - $scope.data.items.splice($scope.dragStartIndex, 1); - } else { - $scope.data.items.splice($scope.dragStartIndex + 1, 1); - } - angular.forEach($scope.data.items, function (e, i) { - e.priority = $scope.minPriority + i; - service.saveFields(e.id, { priority: e.priority }).then((resp) => { - $rootScope.isBusy = false; - $scope.$apply(); - }); - }); - }; - - $scope.updateChildInfos = async function (items) { - $rootScope.isBusy = true; - var resp = await service.updateChildInfos(items); - if (resp && resp.isSucceed) { - $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(); - } - }; - $("#dlg-favorite").on("show.bs.modal", function (event) { - $scope.initCurrentPath(); - }); - }, -]); - -"use strict"; -app.factory("PermissionService", [ - "BaseRestService", - "ApiService", - "CommonService", - function (baseService, apiService, commonService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("permission", true); - var _updateInfos = async function (pages) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), - }; - return await apiService.getApiResult(req); - }; - - var _updateChildInfos = async function (pages) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-child-infos", - data: JSON.stringify(pages), - }; - return await apiService.getApiResult(req); - }; - - serviceFactory.updateInfos = _updateInfos; - serviceFactory.updateChildInfos = _updateChildInfos; - return serviceFactory; - }, -]); - -"use strict"; -app.factory("RestPortalPageNavigationService", [ - "BaseRestService", - "ApiService", - "CommonService", - function (baseService, apiService, commonService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("portal-page-navigation", true); - - 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 = "/portal/role/list"; - $scope.createUrl = `/portal/mix-database-data/create?mixDatabaseName=sys_permission&dataId=default&parentId=${$scope.viewmodel.id}&parentType=Role&backUrl=${backUrl}`; - $scope.updateUrl = "/portal/mix-database-data/details"; - }; - - $scope.createRole = async function () { - $rootScope.isBusy = true; - var result = await service.createRole($scope.role.name); - if (result.isSucceed) { - $scope.role.name = ""; - $scope.getList(); - } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - }, -]); + }, +]); "use strict"; app.factory("RoleService", [ @@ -5026,13 +4431,14 @@ app.factory("RoleService", [ ]); "use strict"; -app.controller("ServiceController", [ +app.controller("PagePostController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "RestMixDatabasePortalService", + "PagePostRestService", + "PostRestService", "ApiService", "CommonService", function ( @@ -5042,9 +4448,10 @@ app.controller("ServiceController", [ $routeParams, $location, service, + postService, commonService ) { - BaseODataCtrl.call( + BaseCtrl.call( this, $scope, $rootScope, @@ -5052,76 +4459,44 @@ app.controller("ServiceController", [ ngAppSettings, service ); - $scope.defaultId = "default"; - $scope.parentId = null; - $scope.parentType = null; $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $rootScope.globalSettings; - $scope.canDrag = - $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - $scope.init = async function () { - $scope.mixDatabaseId = $routeParams.mixDatabaseId; - $scope.mixDatabaseName = $routeParams.mixDatabaseName; - $scope.dataId = $routeParams.dataId; - }; - $scope.saveSuccessCallback = function () { - $rootScope.isBusy = false; - $scope.$apply(); - // if($scope.parentId){ - // $location.url('/portal/mix-database-data/details?dataId='+ $scope.parentId); - // } - // else{ - // $location.url('/portal/mix-database-data/list?mixDatabaseId='+ $scope.viewmodel.mixDatabaseId); - // } - }; - $scope.getList = async function () { - $rootScope.isBusy = true; - $scope.mixDatabaseId = $routeParams.mixDatabaseId; - $scope.mixDatabaseName = $routeParams.mixDatabaseName; - var type = $routeParams.type; - var parentId = $routeParams.parentId; - var response = await service.getList( - "read", - $scope.request, - $scope.mixDatabaseId, - $scope.mixDatabaseName, - type, - parentId - ); + $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 !== "0"; - if (response) { - $scope.data = response; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors("Failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } + $scope.request.orderBy === "Priority" && + $scope.request.direction === "Asc"; + $scope.createUrl = + $routeParams.post_type === "gallery" + ? "/portal/post/create-gallery" + : `/portal/post/create?page_ids=${$scope.pageIds}&module_ids=${$scope.moduleIds}&type=${$scope.type}&template=${$scope.template}`; + $scope.updateUrl = + $routeParams.post_type === "gallery" + ? "/portal/post/gallery-details" + : "/portal/post/details"; }; - $scope.getSingle = async function () { + $scope.getList = async function (pageIndex) { + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } $rootScope.isBusy = true; - var id = $routeParams.id || $scope.defaultId; - $scope.mixDatabaseId = $routeParams.mixDatabaseId; - $scope.mixDatabaseName = $routeParams.mixDatabaseName; - var resp = await service.getSingle("portal", [ - id, - $scope.mixDatabaseId, - $scope.mixDatabaseName, - ]); - if (resp) { - $scope.viewmodel = resp; - $scope.viewmodel.parentType = $scope.parentType; - $scope.viewmodel.parentId = $scope.parentId; + 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.isSucceed) { + $scope.data = response.data; $rootScope.isBusy = false; $scope.$apply(); } else { - if (resp) { - $rootScope.showErrors("Failed"); - } + $rootScope.showErrors(response.errors); $rootScope.isBusy = false; $scope.$apply(); } @@ -5130,28 +4505,23 @@ app.controller("ServiceController", [ item.editUrl = "/portal/post/details/" + item.id; $rootScope.preview("post", item, item.title, "modal-lg"); }; - $scope.edit = function (data) { - $scope.goToPath( - "/portal/mix-database-data/details?dataId=" + - data.id + - "&mixDatabaseId=" + - $scope.mixDatabaseId - ); - }; - $scope.remove = function (data) { + $scope.remove = function (pageId, postId) { $rootScope.showConfirm( $scope, "removeConfirmed", - [data.id], + [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 (dataId) { + $scope.removeConfirmed = async function (id) { $rootScope.isBusy = true; - var result = await service.delete([dataId]); + var result = await service.delete(id); if (result.isSucceed) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -5179,264 +4549,16 @@ app.controller("ServiceController", [ $scope.$apply(); } }; - }, -]); - -"use strict"; -app.controller("SocialFeedController", [ - "$rootScope", - "$scope", - "$http", - "PostRestService", - function ($rootScope, $scope, $http, postService) { - $scope.types = ["Facebook", "Instagram"]; - $scope.isInit = false; - $scope.defaultPost = null; - $scope.defaultProperty = { - name: null, - dataType: 7, - value: "", - }; - $scope.data = []; - $scope.errors = []; - $scope.socialSettings = { - app_id: null, - page_id: null, - app_secret: null, - access_token: "", - page: [], - data: [], - posts: [], - show_login: true, - errors: [], - }; - $scope.init = async function () { - window.fbAsyncInit = function () { - FB.init({ - appId: $rootScope.getConfiguration("FacebookAppId"), - autoLogAppEvents: true, - xfbml: true, - version: "v3.2", - }); - }; - $scope.socialSettings = { - app_id: $rootScope.localizeSettings.data.FacebookAppId, - page_id: $rootScope.localizeSettings.data.Facebook_Page_Id, - app_secret: $rootScope.localizeSettings.data.FacebookAppSecret, - access_token: $rootScope.localizeSettings.data.FacebookAccessToken, - show_login: true, - errors: [], - }; - if ($scope.socialSettings.access_token) { - $scope.socialSettings.show_login = false; - $scope.loadPages(); - } - postService.getSingle(["portal"]).then((resp) => { - $scope.defaultPost = resp.data; - }); - }; - - // This function is called when someone finishes with the Login - // Button. See the onlogin handler attached to it in the sample - // code below. - $scope.login = function () { - FB.login( - function (response) { - // handle the response - $scope.statusChangeCallback(response); - }, - { - scope: "email, manage_pages", - return_scopes: true, - } - ); - }; - - $scope.statusChangeCallback = function (response) { - // The response object is returned with a status column that lets the - // app know the current login status of the person. - // Full docs on the response object can be found in the documentation - // for FB.getLoginStatus(). - if (response.status === "connected") { - // Logged into your app and Facebook. - $scope.exchangeToken(response); - $scope.loadPages(); - //window.location = '/bo/feed?code=' + response.authResponse.accessToken; - } else { - $scope.socialSettings.show_login = true; - $scope.$apply(); - // The person is not logged into your app or we are unable to tell. - } - }; - - $scope.exchangeToken = function (response) { - var url = - "/oauth/access_token?grant_type=fb_exchange_token&client_id=" + - $scope.socialSettings.app_id + - "&client_secret=" + - $scope.socialSettings.app_secret + - "&fb_exchange_token=" + - response.authResponse.accessToken; - FB.api(url, function (response) { - if (response.access_token) { - $scope.socialSettings.access_token = response.access_token; - } else { - $scope.show_login = true; - $scope.socialSettings.errors = response; - $scope.$apply(); - } - }); - }; - $scope.loadFeeds = function (url) { - $scope.socialSettings.errors = ""; - $scope.socialSettings.posts = []; - url = - url || - "/" + - $scope.socialSettings.page_id + - "/posts?access_token=" + - $scope.socialSettings.access_token + - "&columns=type,name,story,full_picture,created_time,permalink_url,message,description,caption,attachments{media,type,target,subattachments},shares.summary(true).limit(0),likes.summary(true).limit(0),comments.summary(true).limit(0)&limit=10"; + $scope.updateInfos = async function (index) { + $scope.data.items.splice(index, 1); $rootScope.isBusy = true; - FB.api(url, function (response) { - if (response.data) { - $scope.socialSettings.data = response.data; - angular.forEach(response.data, function (e, i) { - var post = $scope.parsePost(e); - $scope.socialSettings.posts.push(post); - }); - if (response.paging) { - $scope.socialSettings.nextUrl = response.paging.next; - $scope.socialSettings.prevUrl = response.paging.previous; - } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $scope.socialSettings.show_login = true; - $rootScope.isBusy = false; - $scope.socialSettings.errors = response; - $scope.$apply(); - } - }); - }; - $scope.loadPages = function () { - $scope.socialSettings.errors = ""; - var url = - "/me/accounts?access_token=" + - $scope.socialSettings.access_token + - "&columns=id,name"; - FB.api(url, function (response) { - if (response.data) { - $scope.socialSettings.pages = response.data; - $scope.$apply(); - } else { - $scope.socialSettings.show_login = true; - $scope.socialSettings.errors = response; - } - }); - }; - $scope.setAttr = function (e, attrName, attVal) { - $(e).attr(attrName, attVal); - }; - $scope.parsePost = function (post) { - var post = angular.copy($scope.defaultPost); - var prop = angular.copy($scope.defaultProperty); - post.title = "Facebook Id"; - post.name = "facebook_id"; - post.value = post.id; - post.properties.push(prop); - - post.title = post.name || post.id; - post.excerpt = post.message; - post.content = post.description; - post.source = "Facebook"; - post.image = post.full_picture; - post.detailsUrl = post.permalink_url; - var attachments = post.attachments.data[0]; - - if (attachments.media) { - var media = $scope.parseMedia(attachments.media, attachments.type); - if (media) { - post.mediaNavs.push({ - media: media, - specificulture: $rootScope.localizeSettings.lang, - image: media.fullPath, - }); - } - } - - if (attachments.subattachments) { - var medias = $scope.parseMedias(attachments.subattachments.data); - angular.forEach(medias, function (e, i) { - post.mediaNavs.push({ - media: e, - specificulture: $rootScope.localizeSettings.lang, - image: e.fullPath, - }); - }); - } - return post; - }; - $scope.parseMedias = function (data) { - var result = []; - if (data) { - angular.forEach(data, function (e, i) { - var media = $scope.parseMedia(e.media, e.type); - if (media) { - result.push(media); - } - }); - } - return result; - }; - $scope.parseMedia = function (media, type) { - if (media) { - var src = ""; - switch (type) { - case "video_autoplay": - src = media.source; - break; - case "profile_media": - case "photo": - default: - src = media.image.src; - break; - } - try { - if (src) { - var index = src.lastIndexOf("/"); - var ext = src.match(/.(?:jpg|gif|png|gif|jpeg|mp4)/)[0]; - // if valid file - if (ext) { - var eIndex = src.indexOf(ext); - var filename = src.substring(index + 1, eIndex); - var media = { - fileName: filename, - fileFolder: "Facebook", - extension: ext, - targetUrl: src, - fullPath: src, - fileType: type, - source: "Facebook", - }; - - return media; - } else { - return null; - } - } else { - return null; - } - } catch (err) { - console.log("Cannot parse media", media); - return null; - } + 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; } - }; - $scope.syncPosts = async function () { - $rootScope.isBusy = true; - var resp = await postService.saveList($scope.socialSettings.posts); + var resp = await service.updateInfos($scope.data.items); if (resp && resp.isSucceed) { + $scope.activedPage = resp.data; $rootScope.showMessage("success", "success"); $rootScope.isBusy = false; $scope.$apply(); @@ -5452,41 +4574,58 @@ app.controller("SocialFeedController", [ ]); "use strict"; -app.controller("StoreController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "CryptoService", - "ThemeService", - "StoreService", - function ( - $scope, - $rootScope, - ngAppSettings, - cryptoService, - themeService, - service - ) { - }, +app.factory("PagePostRestService", [ + "$rootScope", + "ApiService", + "CommonService", + "BaseService", + function($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("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("TemplateController", [ +app.controller("PostController", [ "$scope", "$rootScope", - "$routeParams", "$location", + "$filter", "ngAppSettings", - "AuthService", - "TemplateService", + "$routeParams", + "PostRestService", + "UrlAliasService", + "RestMixDatabaseDataPortalService", + "RestMixDatabaseColumnPortalService", function ( $scope, $rootScope, - $routeParams, $location, + $filter, ngAppSettings, - authService, - service + $routeParams, + service, + urlAliasService, + dataService, + columnService ) { BaseRestCtrl.call( this, @@ -5497,685 +4636,407 @@ app.controller("TemplateController", [ ngAppSettings, service ); - BaseHub.call(this, $scope); - $scope.folderTypes = [ - "Masters", - "Layouts", - "Pages", - "Modules", - "Forms", - "Edms", - "Products", - "Posts", - "Widgets", - ]; - $scope.isInitHub = false; - $scope.room = null; - $scope.members = []; - $scope.activedPane = null; - $scope.canRename = true; - $scope.user = null; - $scope.selectPane = function (pane) { - $scope.activedPane = pane; - }; - $scope.init = async function () { - authService.fillAuthData().then(function () { - $scope.user = { - username: authService.authentication.info.username, - avatar: authService.authentication.info.userData.avatar, - }; - $scope.startConnection("editFileHub", () => { - let id = $routeParams.id || $rootScope.generateUUID(); - $scope.room = `Template-${id}`; - $scope.joinRoom(); - }); - }); + $scope.viewmodelType = "post"; + $scope.additionalData = null; + $scope.createUrl = "/portal/post/create?"; + $scope.selectedCategories = []; + $scope.selectedTags = []; + $scope.postType = { + databaseName: "", + title: "All", }; - $scope.loadFolder = function (d) { - $location.url( - "/portal/template/list/" + - $routeParams.themeId + - "?folderType=" + - encodeURIComponent(d) - ); + $scope.cateRequest = angular.copy(ngAppSettings.request); + $scope.postTypeRequest = angular.copy(ngAppSettings.request); + $scope.postTypeRequest.mixDatabaseName = "post_type"; + $scope.postTypeRequest.orderBy = "Priority"; + $scope.postTypeRequest.direction = "Asc"; + + $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.postType = $routeParams.type; + } + if ($routeParams.page_ids) { + $scope.createUrl = `${$scope.createUrl}&page_ids=${$routeParams.page_ids}`; + } + $scope.pageName = "postList"; + await $scope.loadPostTypes(); + await $scope.loadCategories(); + $scope.getList(); }; - $scope.loadParams = async function () { - $rootScope.isBusy = true; - $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; - $scope.themeId = $routeParams.themeId; + $scope.loadCategories = async function () { + $scope.cateRequest.mixDatabaseName = "sys_category"; + var response = await dataService.getList($scope.cateRequest); + if (response.isSucceed) { + $scope.categories = response.data; + $scope.isBusy = false; + $scope.$apply(); + } }; - $scope.getSingle = async function () { - $rootScope.isBusy = true; - var id = $routeParams.id; - $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; - var themeId = $routeParams.themeId; - $scope.listUrl = - "/portal/template/list/" + - themeId + - "?folderType=" + - encodeURIComponent($scope.folderType); - if (id) { - var resp = await service.getSingle([id], { - folderType: $scope.folderType, - themeId: themeId, - }); - if (resp && resp.isSucceed) { - $scope.viewmodel = resp.data; - $scope.canRename = - $scope.viewmodel.id === 0 || - $scope.viewmodel.fileName.indexOf("Copy") === 0; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } - } else { - var resp = await service.getDefault(); - if (resp && resp.isSucceed) { - resp.data.themeId = themeId; - resp.data.folderType = $scope.folderType; - $scope.viewmodel = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.loadPostTypes = async function () { + let getTypes = await dataService.getList($scope.postTypeRequest); + if (getTypes.isSucceed) { + $scope.postTypes = getTypes.data.items.map((m) => m.obj); + $scope.postTypes.splice( + 0, + 0, + { + databaseName: "", + title: "All", + id: 0, + }, + { + databaseName: "sys_additional_column_post", + title: "Default", + id: 1, } - $rootScope.isBusy = false; - $scope.$apply(); + ); + if ($scope.request.postType) { + $scope.postType = $rootScope.findObjectByKey( + $scope.postTypes, + "databaseName", + $scope.request.postType + ); } + $scope.request.postType = $routeParams.type || ""; + $scope.$apply(); } }; - $scope.copy = async function (id) { + $scope.getDefault = async function (type = null) { $rootScope.isBusy = true; - $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; - var themeId = $routeParams.themeId; - $scope.listUrl = - "/portal/template/list/" + - themeId + - "?folderType=" + - encodeURIComponent($scope.folderType); - var resp = await service.copy(id); - if (resp && resp.isSucceed) { - $location.url( - `/portal/template/details/${themeId}/${$scope.folderType}/${resp.data.id}` - ); + type = type || $routeParams.type; + var resp = await service.getDefault({ + type: type || "", + template: $routeParams.template || "", + }); + if (resp.isSucceed) { + $scope.viewmodel = resp.data; + 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.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.isSucceed) { - $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.preview = function (item) { + item.editUrl = "/portal/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); }; - $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; + $scope.onSelectType = function () { + if ($scope.viewmodel) { + $scope.viewmodel.type = $scope.postType.databaseName; + $scope.loadAdditionalData(); } - 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.selectedExport = { - isIncludeAssets: true, - isIncludeTemplates: true, - isIncludeConfigurations: true, - isIncludePermissions: true, - pages: [], - modules: [], - mixDatabases: [], - }; - - $scope.getSingleSuccessCallback = function () { - $scope.assets = null; - $scope.theme = null; - }; - $scope.save = async function (viewmodel) { - var form = document.getElementById("form-portal"); - var frm = new FormData(); - var url = service.prefixUrl + "/save"; - - $rootScope.isBusy = true; - // Looping over all files and add it to FormData object - frm.append("assets", form["assets"].files[0]); - frm.append("theme", form["theme"].files[0]); - // Adding one more key to FormData object - frm.append("model", angular.toJson(viewmodel || $scope.viewmodel)); - - var response = await service.ajaxSubmitForm(frm, url); - if (response.isSucceed) { - $scope.viewmodel = response.data; - $rootScope.isBusy = false; - $location.url($scope.referrerUrl); - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + $scope.request.postType = $scope.postType.databaseName; + $scope.createUrl = `/portal/post/create?type=${$scope.request.postType}`; + if ($routeParams.template) { + $scope.createUrl += `&template=${$routeParams.template}`; } - }; - $scope.syncTemplates = async function (id) { - $rootScope.isBusy = true; - var response = await service.syncTemplates(id); - if (response.isSucceed) { - $scope.viewmodel = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + if ( + $scope.postType.databaseName && + (!$scope.viewmodel || !$scope.viewmodel.id) + ) { + $scope.getDefault($scope.request.postType); + } + if ($scope.pageName == "postList") { + $scope.getList(); } }; - - $scope.export = async function () { - var id = $routeParams.id; - $rootScope.isBusy = true; - var response = await service.export(id, $scope.selectedExport); - if (response.isSucceed) { + $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.getList($scope.request); + if (resp && resp.isSucceed) { + let result = []; + 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; - window.open(response.data, "_blank"); $scope.$apply(); + return resp.data; } else { - $rootScope.showErrors(response.errors); + $rootScope.showErrors(getData.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.saveSuccessCallback = function () { - commonService.initAllSettings().then(function () { - $location.path("/portal/theme/list"); - $rootScope.isBusy = false; - $scope.$apply(); - }); - }; - $scope.removeCallback = function () { - commonService.initAllSettings().then(function () { - $location.path("/portal/theme/list"); + $scope.saveFailCallback = function () { + angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { + if (nav.isActived) { + $rootScope.decryptMixDatabase( + nav.mixDatabase.attributes, + nav.mixDatabase.postData.items + ); + } }); }; - - $scope.getExportData = async function () { - var id = $routeParams.id; - var resp = await service.getExportData(id); - if (resp && resp.isSucceed) { - $scope.exportData = resp.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.saveSuccessCallback = async function () { + if ($scope.additionalData) { + $scope.additionalData.isClone = $scope.viewmodel.isClone; + $scope.additionalData.cultures = $scope.viewmodel.cultures; + $scope.additionalData.parentId = $scope.viewmodel.id; + $scope.additionalData.parentType = "Post"; + let result = await dataService.save($scope.additionalData); + if (!result.isSucceed) { + $rootScope.showErrors(result.errors); + } else { + $scope.additionalData = result.data; + $scope.saveColumns(); } - $rootScope.isBusy = false; - $scope.$apply(); } + $rootScope.isBusy = false; + $scope.$apply(); }; - $scope.generateSEO = function () { - $scope.viewmodel.name = $rootScope.generateKeyword( - $scope.viewmodel.title, - "-" - ); + $scope.saveColumns = async function () { + let result = await columnService.saveMany($scope.additionalData.columns); + if (result.isSucceed) { + $rootScope.showMessage("success", "success"); + } }; - }, -]); - -"use strict"; -app.controller("UserController", [ - "$scope", - "$rootScope", - "ngAppSettings", - "$routeParams", - "$timeout", - "$location", - "AuthService", - "UserServices", - "RestMixDatabaseDataPortalService", - function ( - $scope, - $rootScope, - ngAppSettings, - $routeParams, - $timeout, - $location, - authService, - userServices, - dataService - ) { - $scope.request = { - pageSize: "10", - pageIndex: 0, - status: "Published", - orderBy: "CreatedDateTime", - direction: "Desc", - fromDate: null, - toDate: null, - keyword: "", - }; - - $scope.mediaFile = { - file: null, - fullPath: "", - folder: "User", - title: "", - description: "", - }; - $scope.activedUser = null; - $scope.relatedUsers = []; - $rootScope.isBusy = false; - $scope.data = { - pageIndex: 0, - pageSize: 1, - totalItems: 0, - }; - $scope.errors = []; + $scope.getSingleSuccessCallback = async function () { + $scope.defaultThumbnailImgWidth = + ngAppSettings.localizeSettings.DefaultThumbnailImgWidth; + $scope.defaultThumbnailImgHeight = + ngAppSettings.localizeSettings.DefaultThumbnailImgHeight; - $scope.range = function (max) { - var input = []; - for (var i = 1; i <= max; i += 1) input.push(i); - return input; - }; + $scope.defaultFeatureImgWidth = + ngAppSettings.localizeSettings.DefaultFeatureImgWidth; + $scope.defaultFeatureImgHeight = + ngAppSettings.localizeSettings.DefaultFeatureImgHeight; - $scope.loadUser = async function () { - $rootScope.isBusy = true; - var id = $routeParams.id; - var response = await userServices.getUser(id, "portal"); - if (response.isSucceed) { - $scope.activedUser = response.data; - $rootScope.isBusy = false; - if (!$rootScope.isInRole("SuperAdmin")) { - $scope.activedUser.userRoles = $scope.activedUser.userRoles.filter( - (role) => role.description != "SuperAdmin" + $scope.request.postType = $scope.viewmodel.type; + var moduleIds = $routeParams.module_ids; + var pageIds = $routeParams.page_ids; + $scope.postType = $rootScope.findObjectByKey( + $scope.postTypes, + "databaseName", + $scope.request.postType + ); + await $scope.loadCategories(); + $scope.loadAdditionalData(); + if (moduleIds) { + for (var moduleId of moduleIds.split(",")) { + var moduleNav = $rootScope.findObjectByKey( + $scope.viewmodel.modules, + "moduleId", + moduleId ); + if (moduleNav) { + moduleNav.isActived = true; + } } - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); } - }; + if (pageIds) { + for (var pageId of pageIds.split(",")) { + var pageNav = $rootScope.findObjectByKey( + $scope.viewmodel.pages, + "pageId", + pageId + ); + if (pageNav) { + pageNav.isActived = true; + } + } + } + if ($scope.viewmodel.sysCategories) { + angular.forEach($scope.viewmodel.sysCategories, function (e) { + e.attributeData.obj.isActived = true; + $scope.selectedCategories.push(e.attributeData.obj); + }); + } - $scope.loadMyProfile = async function () { - $rootScope.isBusy = true; - var response = await userServices.getMyProfile(); - if (response.isSucceed) { - $scope.activedUser = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + if ($scope.viewmodel.sysTags) { + angular.forEach($scope.viewmodel.sysTags, function (e) { + e.attributeData.obj.isActived = true; + $scope.selectedCategories.push(e.attributeData.obj); + }); + } + if ($routeParams.template) { + $scope.viewmodel.view = $rootScope.findObjectByKey( + $scope.viewmodel.templates, + "fileName", + $routeParams.template + ); } }; - - $scope.loadUsers = async function (pageIndex) { - authService.fillAuthData().then(() => { - if ($rootScope.isInRoles(["SuperAdmin", "Admin"])) { - $scope.createUrl = "/portal/user/create"; - } - }); - - if (pageIndex !== undefined) { - $scope.request.pageIndex = pageIndex; + $scope.loadAdditionalData = async function () { + const obj = { + parentType: "Post", + parentId: $scope.viewmodel.id, + databaseName: $scope.viewmodel.type || "", + }; + const getData = await dataService.getAdditionalData(obj); + if (getData.isSucceed) { + $scope.additionalData = getData.data; + $scope.$apply(); } - $rootScope.isBusy = true; - var resp = await userServices.getUsers($scope.request); - if (resp && resp.isSucceed) { - $scope.data = resp.data; - if (!$rootScope.isInRole("SuperAdmin")) { - $scope.data.items = $scope.data.items.filter( - (user) => - user.userRoles.length == 0 || - user.userRoles[0].role.name != "SuperAdmin" + }; + $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) + "..."; + } } - $.each($scope.data.items, function (i, user) { - $.each($scope.data, function (i, e) { - if (e.userId === user.id) { - user.isHidden = true; - } - }); - }); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + 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; } - $rootScope.isBusy = false; - $scope.$apply(); } }; - - $scope.removeUser = function (id) { - $rootScope.showConfirm( - $scope, - "removeUserConfirmed", - [id], - null, - "Remove User", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - - $scope.removeUserConfirmed = async function (id) { - $rootScope.isBusy = true; - var result = await userServices.removeUser(id); - if (result.isSucceed) { - $scope.loadUsers(); + $scope.addAlias = async function () { + var getAlias = await urlAliasService.getSingle(); + if (getAlias.isSucceed) { + $scope.viewmodel.urlAliases.push(getAlias.data); + $rootScope.isBusy = false; + $scope.$apply(); } else { - $rootScope.showMessage("failed"); + $rootScope.showErrors(getAlias.errors); $rootScope.isBusy = false; $scope.$apply(); } }; - - $scope.save = async function () { - //if (user.avatar !== user.avatarUrl) { - // user.avatar = user.avatarUrl; - //} - $rootScope.isBusy = true; - var resp = await userServices.saveUser($scope.activedUser); - if (resp && resp.isSucceed) { - $rootScope.showMessage("Update successfully!", "success"); - if ($scope.activedUser.user.id == authService.authentication.info.id) { - authService - .refreshToken( - authService.authentication.refresh_token, - authService.authentication.access_token - ) - .then(() => { - window.location = window.location; - }); - } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); - } + $scope.removeAliasCallback = async function (index) { + $scope.viewmodel.urlAliases.splice(index, 1); + $scope.$apply(); }; - - $scope.saveUserData = async function () { - if ($scope.activedUser.userData) { - $scope.activedUser.userData.parentId = $scope.activedUser.id; - $scope.activedUser.userData.parentType = "User"; - await dataService.save($scope.activedUser.userData); - } + $scope.updateSysCategories = function (data) { + // Loop selected categories + angular.forEach($scope.selectedCategories, function (e) { + // add if not exist in sysCategories + var current = $rootScope.findObjectByKey( + $scope.viewmodel.sysCategories, + "id", + e.id + ); + if (!current) { + $scope.viewmodel.sysCategories.push({ + id: e.id, + parentId: $scope.viewmodel.id, + mixDatabaseName: "sys_category", + }); + } + }); }; - - $scope.register = async function (user) { - $rootScope.isBusy = true; - var resp = await userServices.register(user); - if (resp && resp.isSucceed) { - $scope.activedUser = resp.data; - $rootScope.showMessage("Update successfully!", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.updateSysTags = function (data) { + // Loop selected categories + angular.forEach($scope.selectedTags, function (e) { + // add if not exist in sysCategories + var current = $rootScope.findObjectByKey( + $scope.viewmodel.sysTags, + "id", + e.id + ); + if (!current) { + $scope.viewmodel.sysCategories.push({ + id: e.id, + parentId: $scope.viewmodel.id, + mixDatabaseName: "sys_tag", + }); } - $rootScope.isBusy = false; - $scope.$apply(); - } + }); }; - - $scope.updateRoleStatus = async function (nav) { - var userRole = { - userId: nav.userId, - roleId: nav.roleId, - roleName: nav.description, - isUserInRole: nav.isActived, - }; - $rootScope.isBusy = true; - var resp = await userServices.updateRoleStatus(userRole); - if (resp && resp.isSucceed) { - $rootScope.showMessage("Update successfully!", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); + $scope.validate = function () { + angular.forEach($scope.viewmodel.mixDatabaseNavs, function (nav) { + if (nav.isActived) { + $rootScope.encryptMixDatabase( + nav.mixDatabase.attributes, + nav.mixDatabase.postData.items + ); } - $rootScope.isBusy = false; - $scope.$apply(); - } + }); + return true; }; }, ]); "use strict"; -app.factory("UserServices", [ - "ApiService", - "ngAppSettings", - function (apiService, ngAuthSettings) { - var usersServiceFactory = {}; - var apiUrl = "/account/"; - - var serviceBase = ngAuthSettings.serviceBase; - - var _getUserDemographicInfo = function () { - var url = "/GetUserDemographicInfo"; - var req = { - method: "GET", - url: serviceBase + url, - }; - - return apiService.getApiResult(req); - }; - - var _importUsers = function (strBase64) { - var url = "import-users"; - var req = { - method: "POST", - url: apiUrl + url, - data: JSON.stringify({ strBase64: strBase64 }), - }; - - return apiService.getApiResult(req); - }; - - var _getUsers = function (request) { - var req = { - method: "POST", - url: apiUrl + "list", - data: request, - }; - - return apiService.getApiResult(req); - }; - - var _getUser = async function (id, viewType) { - var apiUrl = "/account/"; - var url = apiUrl + "details/" + viewType; - if (id) { - url += "/" + id; - } - var req = { - method: "GET", - url: url, - }; - return await apiService.getApiResult(req); - }; - - var _getMyProfile = async function () { - var apiUrl = "/account/"; - var url = apiUrl + "my-profile"; - var req = { - method: "GET", - url: url, - }; - return await apiService.getApiResult(req); - }; - - var _updateRoleStatus = function (userInRole) { - var req = { - method: "POST", - url: serviceBase + "/account/user-in-role", - data: JSON.stringify(userInRole), - }; - - return apiService.getApiResult(req); - }; - - var _saveUser = async function (user) { - var apiUrl = "/account/"; - var req = { - method: "POST", - url: apiUrl + "save", - data: JSON.stringify(user), - }; - return await apiService.getApiResult(req); - }; - - var _register = async function (user) { - var apiUrl = "/account/"; - var req = { - method: "POST", - url: apiUrl + "register", - data: JSON.stringify(user), - }; - return await apiService.getApiResult(req); - }; - - var _removeUser = function (userId) { - var req = { - method: "GET", - url: apiUrl + "remove-user/" + userId, - }; - - return apiService.getApiResult(req); - }; - - usersServiceFactory.importUsers = _importUsers; - usersServiceFactory.getUsers = _getUsers; - usersServiceFactory.getUser = _getUser; - usersServiceFactory.getMyProfile = _getMyProfile; - usersServiceFactory.saveUser = _saveUser; - usersServiceFactory.register = _register; - usersServiceFactory.removeUser = _removeUser; - usersServiceFactory.updateRoleStatus = _updateRoleStatus; - usersServiceFactory.getUserDemographicInfo = _getUserDemographicInfo; - return usersServiceFactory; +app.factory("PostRestService", [ + "BaseRestService", + function (baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("post/portal"); + // Define more service methods here + return serviceFactory; }, ]); "use strict"; -app.controller("UrlAliasController", [ +app.controller("ServiceController", [ "$scope", "$rootScope", "ngAppSettings", "$routeParams", "$location", - "UrlAliasService", + "RestMixDatabasePortalService", "ApiService", "CommonService", function ( @@ -6185,10 +5046,9 @@ app.controller("UrlAliasController", [ $routeParams, $location, service, - apiService, commonService ) { - BaseCtrl.call( + BaseODataCtrl.call( this, $scope, $rootScope, @@ -6196,44 +5056,106 @@ app.controller("UrlAliasController", [ ngAppSettings, service ); + $scope.defaultId = "default"; + $scope.parentId = null; + $scope.parentType = null; $scope.cates = ["Site", "System"]; $scope.others = []; $scope.localizeSettings = $rootScope.globalSettings; - $scope.pageId = $routeParams.id; $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; + $scope.init = async function () { + $scope.mixDatabaseId = $routeParams.mixDatabaseId; + $scope.mixDatabaseName = $routeParams.mixDatabaseName; + $scope.dataId = $routeParams.dataId; + }; + $scope.saveSuccessCallback = function () { + $rootScope.isBusy = false; + $scope.$apply(); + // if($scope.parentId){ + // $location.url('/portal/mix-database-data/details?dataId='+ $scope.parentId); + // } + // else{ + // $location.url('/portal/mix-database-data/list?mixDatabaseId='+ $scope.viewmodel.mixDatabaseId); + // } + }; $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.mixDatabaseId = $routeParams.mixDatabaseId; + $scope.mixDatabaseName = $routeParams.mixDatabaseName; + var type = $routeParams.type; + var parentId = $routeParams.parentId; + var response = await service.getList( + "read", + $scope.request, + $scope.mixDatabaseId, + $scope.mixDatabaseName, + type, + parentId + ); $scope.canDrag = $scope.request.orderBy !== "Priority" || $scope.request.direction !== "0"; - if (response.isSucceed) { - $scope.data = response.data; + if (response) { + $scope.data = response; $rootScope.isBusy = false; $scope.$apply(); } else { - $rootScope.showErrors(response.errors); + $rootScope.showErrors("Failed"); $rootScope.isBusy = false; $scope.$apply(); } }; - $scope.remove = function (id) { + $scope.getSingle = async function () { + $rootScope.isBusy = true; + var id = $routeParams.id || $scope.defaultId; + $scope.mixDatabaseId = $routeParams.mixDatabaseId; + $scope.mixDatabaseName = $routeParams.mixDatabaseName; + var resp = await service.getSingle("portal", [ + id, + $scope.mixDatabaseId, + $scope.mixDatabaseName, + ]); + if (resp) { + $scope.viewmodel = resp; + $scope.viewmodel.parentType = $scope.parentType; + $scope.viewmodel.parentId = $scope.parentId; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors("Failed"); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.preview = function (item) { + item.editUrl = "/portal/post/details/" + item.id; + $rootScope.preview("post", item, item.title, "modal-lg"); + }; + $scope.edit = function (data) { + $scope.goToPath( + "/portal/mix-database-data/details?dataId=" + + data.id + + "&mixDatabaseId=" + + $scope.mixDatabaseId + ); + }; + $scope.remove = function (data) { $rootScope.showConfirm( $scope, "removeConfirmed", - [id], + [data.id], null, "Remove", "Deleted data will not able to recover, are you sure you want to delete this item?" ); }; - $scope.removeConfirmed = async function (id) { + $scope.removeConfirmed = async function (dataId) { $rootScope.isBusy = true; - var result = await service.delete(id); + var result = await service.delete([dataId]); if (result.isSucceed) { if ($scope.removeCallback) { $rootScope.executeFunctionByName( @@ -6250,23 +5172,13 @@ app.controller("UrlAliasController", [ } }; - $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.isSucceed) { - $scope.activedPage = resp.data; - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; + $scope.saveOthers = async function () { + var response = await service.saveList($scope.others); + if (response.isSucceed) { + $scope.getList(); $scope.$apply(); } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } + $rootScope.showErrors(response.errors); $rootScope.isBusy = false; $scope.$apply(); } @@ -6275,789 +5187,1519 @@ app.controller("UrlAliasController", [ ]); "use strict"; -app.factory("UrlAliasService", [ +app.controller("StoreController", [ + "$scope", "$rootScope", - "ApiService", - "CommonService", - "BaseService", - function ($rootScope, apiService, commonService, baseService) { - var serviceFactory = Object.create(baseService); - serviceFactory.init("url-alias"); - - var _updateInfos = async function (pages) { - var req = { - method: "POST", - url: this.prefixUrl + "/update-infos", - data: JSON.stringify(pages), - }; - return await apiService.getApiResult(req); - }; - serviceFactory.updateInfos = _updateInfos; - return serviceFactory; + "ngAppSettings", + "CryptoService", + "ThemeService", + "StoreService", + function ( + $scope, + $rootScope, + ngAppSettings, + cryptoService, + themeService, + service + ) { }, ]); "use strict"; -function PageDetailsController($scope, $element, $attrs) { - var ctrl = this; - ctrl.activedPage = null; - ctrl.relatedPages = []; - ctrl.data = []; - ctrl.errors = []; - ctrl.range = function (max) { - var input = []; - for (var i = 1; i <= max; i += 1) input.push(i); - return input; - }; - ctrl.loadPage = function (pageId) { - ctrl.isBusy = true; - var url = "/" + ctrl.currentLanguage + "/page/details/be/" + pageId; //byPage/' + pageId; - ctrl.localizeSettings.method = "GET"; - ctrl.localizeSettings.url = url; // + '/true'; - ctrl.localizeSettings.data = ctrl.request; - $.ajax(ctrl.localizeSettings).done(function (response) { - if (response.isSucceed) { - ctrl.activedPage = response.data; - ctrl.initEditor(); - } - ctrl.isBusy = false; - ctrl.$apply(); - }); - }; - ctrl.loadPages = function (pageIndex) { - ctrl.isBusy = true; - if (pageIndex !== undefined) { - ctrl.request.pageIndex = pageIndex; - } - if (ctrl.request.fromDate !== null) { - ctrl.request.fromDate = ctrl.request.fromDate.toISOString(); - } - if (ctrl.request.toDate !== null) { - ctrl.request.toDate = ctrl.request.toDate.toISOString(); - } - var url = "/" + ctrl.currentLanguage + "/page/list"; //byPage/' + pageId; - ctrl.localizeSettings.method = "POST"; - ctrl.localizeSettings.url = url; // + '/true'; - ctrl.localizeSettings.data = ctrl.request; - $.ajax(ctrl.localizeSettings).done(function (response) { - ctrl.data = response.data; - - $.each(ctrl.data.items, function (i, page) { - $.each(ctrl.activedPages, function (i, e) { - if (e.pageId === page.id) { - page.isHidden = true; - } +app.controller("SocialFeedController", [ + "$rootScope", + "$scope", + "$http", + "PostRestService", + function ($rootScope, $scope, $http, postService) { + $scope.types = ["Facebook", "Instagram"]; + $scope.isInit = false; + $scope.defaultPost = null; + $scope.defaultProperty = { + name: null, + dataType: 7, + value: "", + }; + $scope.data = []; + $scope.errors = []; + $scope.socialSettings = { + app_id: null, + page_id: null, + app_secret: null, + access_token: "", + page: [], + data: [], + posts: [], + show_login: true, + errors: [], + }; + $scope.init = async function () { + window.fbAsyncInit = function () { + FB.init({ + appId: $rootScope.getConfiguration("FacebookAppId"), + autoLogAppEvents: true, + xfbml: true, + version: "v3.2", }); + }; + $scope.socialSettings = { + app_id: $rootScope.localizeSettings.data.FacebookAppId, + page_id: $rootScope.localizeSettings.data.Facebook_Page_Id, + app_secret: $rootScope.localizeSettings.data.FacebookAppSecret, + access_token: $rootScope.localizeSettings.data.FacebookAccessToken, + show_login: true, + errors: [], + }; + if ($scope.socialSettings.access_token) { + $scope.socialSettings.show_login = false; + $scope.loadPages(); + } + postService.getSingle(["portal"]).then((resp) => { + $scope.defaultPost = resp.data; }); - ctrl.isBusy = false; - setTimeout(function () { - $('[data-bs-toggle="popover"]').popover({ - html: true, - content: function () { - var content = $(this).next(".popover-body"); - return $(content).html(); - }, - title: function () { - var title = $(this).attr("data-popover-content"); - return $(title).children(".popover-heading").html(); - }, - }); - }, 200); - ctrl.$apply(); - }); - }; + }; - ctrl.removePage = function (pageId) { - if (confirm("Are you sure!")) { - var url = "/" + ctrl.currentLanguage + "/page/delete/" + pageId; - $.ajax({ - method: "GET", - url: url, - success: function (data) { - ctrl.loadPages(); - ctrl.$apply(); + // This function is called when someone finishes with the Login + // Button. See the onlogin handler attached to it in the sample + // code below. + $scope.login = function () { + FB.login( + function (response) { + // handle the response + $scope.statusChangeCallback(response); }, - error: function (a, b, c) {}, - }); - } - }; - ctrl.savePage = function (page) { - var url = "/" + ctrl.currentLanguage + "/page/save"; - $.ajax({ - method: "POST", - url: url, - data: page, - success: function (data) { - //ctrl.loadPages(); - if (data.isSucceed) { - alert("success"); - } else { - alert("failed! " + data.errors); + { + scope: "email, manage_pages", + return_scopes: true, } - }, - error: function (a, b, c) {}, - }); - }; - - ctrl.changeMedia = function (media) { - var currentItem = null; - if (ctrl.activedPage.mediaNavs === undefined) { - ctrl.activedPage.mediaNavs = []; - } - $.each(ctrl.activedPage.mediaNavs, function (i, e) { - if (e.mediaId === media.id) { - e.isActived = media.isActived; - currentItem = e; - return false; - } - }); - if (currentItem === null) { - currentItem = { - description: media.description !== "undefined" ? media.description : "", - image: media.fullPath, - mediaId: media.id, - page: ctrl.activedPage.id, - specificulture: media.specificulture, - position: 0, - priority: ctrl.activedMedias.length + 1, - isActived: true, - }; - media.isHidden = true; - ctrl.activedPage.mediaNavs.push(currentItem); - } - }; + ); + }; - ctrl.changePage = function (page) { - var currentItem = null; - $.each(ctrl.activedPage.pageNavs, function (i, e) { - if (e.relatedPageId === page.id) { - e.isActived = page.isActived; - currentItem = e; - return false; + $scope.statusChangeCallback = function (response) { + // The response object is returned with a status column that lets the + // app know the current login status of the person. + // Full docs on the response object can be found in the documentation + // for FB.getLoginStatus(). + if (response.status === "connected") { + // Logged into your app and Facebook. + $scope.exchangeToken(response); + $scope.loadPages(); + //window.location = '/bo/feed?code=' + response.authResponse.accessToken; + } else { + $scope.socialSettings.show_login = true; + $scope.$apply(); + // The person is not logged into your app or we are unable to tell. } - }); - if (currentItem === null) { - currentItem = { - relatedPageId: page.id, - sourcePageId: $("#page-id").val(), - specificulture: page.specificulture, - priority: ctrl.activedPage.pageNavs.length + 1, - page: page, - isActived: true, - }; - page.isHidden = true; - ctrl.activedPage.pageNavs.push(currentItem); - } - }; + }; - ctrl.addProperty = function (type) { - var i = $(".property").length; - $.ajax({ - method: "GET", - url: + $scope.exchangeToken = function (response) { + var url = + "/oauth/access_token?grant_type=fb_exchange_token&client_id=" + + $scope.socialSettings.app_id + + "&client_secret=" + + $scope.socialSettings.app_secret + + "&fb_exchange_token=" + + response.authResponse.accessToken; + FB.api(url, function (response) { + if (response.access_token) { + $scope.socialSettings.access_token = response.access_token; + } else { + $scope.show_login = true; + $scope.socialSettings.errors = response; + $scope.$apply(); + } + }); + }; + $scope.loadFeeds = function (url) { + $scope.socialSettings.errors = ""; + $scope.socialSettings.posts = []; + url = + url || "/" + - ctrl.currentLanguage + - "/Portal/" + - type + - "/AddEmptyProperty/" + - i, - success: function (data) { - $("#tbl-properties > tbody").append(data); - $(data).find(".prop-data-type").trigger("change"); - }, - error: function (a, b, c) {}, - }); - ctrl.updateHero = function (hero, prop, value) { - hero[prop] = value; + $scope.socialSettings.page_id + + "/posts?access_token=" + + $scope.socialSettings.access_token + + "&columns=type,name,story,full_picture,created_time,permalink_url,message,description,caption,attachments{media,type,target,subattachments},shares.summary(true).limit(0),likes.summary(true).limit(0),comments.summary(true).limit(0)&limit=10"; + $rootScope.isBusy = true; + FB.api(url, function (response) { + if (response.data) { + $scope.socialSettings.data = response.data; + angular.forEach(response.data, function (e, i) { + var post = $scope.parsePost(e); + $scope.socialSettings.posts.push(post); + }); + if (response.paging) { + $scope.socialSettings.nextUrl = response.paging.next; + $scope.socialSettings.prevUrl = response.paging.previous; + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $scope.socialSettings.show_login = true; + $rootScope.isBusy = false; + $scope.socialSettings.errors = response; + $scope.$apply(); + } + }); }; - - ctrl.deleteHero = function (hero) { - var idx = ctrl.list.indexOf(hero); - if (idx >= 0) { - ctrl.list.splice(idx, 1); - } + $scope.loadPages = function () { + $scope.socialSettings.errors = ""; + var url = + "/me/accounts?access_token=" + + $scope.socialSettings.access_token + + "&columns=id,name"; + FB.api(url, function (response) { + if (response.data) { + $scope.socialSettings.pages = response.data; + $scope.$apply(); + } else { + $scope.socialSettings.show_login = true; + $scope.socialSettings.errors = response; + } + }); }; - }; - - angular.module(appName).component("pageDetails", { - templateUrl: "pageDetails.html", - controller: PageDetailsController, - }); -} + $scope.setAttr = function (e, attrName, attVal) { + $(e).attr(attrName, attVal); + }; + $scope.parsePost = function (post) { + var post = angular.copy($scope.defaultPost); + var prop = angular.copy($scope.defaultProperty); + post.title = "Facebook Id"; + post.name = "facebook_id"; + post.value = post.id; + post.properties.push(prop); -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: "&", - }, -}); + post.title = post.name || post.id; + post.excerpt = post.message; + post.content = post.description; + post.source = "Facebook"; + post.image = post.full_picture; + post.detailsUrl = post.permalink_url; + var attachments = post.attachments.data[0]; -app.component("appSettingsDefault", { - templateUrl: - "/mix-app/views/app-portal/pages/app-settings/components/default/view.html", - controller: [ - "$rootScope", - "ngAppSettings", - function ($rootScope, ngAppSettings) { - var ctrl = this; - ctrl.$onInit = function () { - ctrl.properties = $.parseJSON( - ctrl.appSettings.GlobalSettings.DefaultPostAttr - ); - ctrl.trackedProperties = $.parseJSON( - ctrl.appSettings.GlobalSettings.DefaultPostAttr - ); - ctrl.dataTypes = $rootScope.globalSettings.dataTypes; - }; - ctrl.addPostProperty = function () { - ctrl.properties.push({ - priority: 0, - name: "", - value: null, - dataType: "7", - }); - }; - ctrl.$doCheck = function () { - if (ctrl.trackedProperties != ctrl.properties) { - ctrl.trackedProperties = angular.copy(ctrl.properties); - ctrl.appSettings.GlobalSettings.DefaultPostAttr = JSON.stringify( - ctrl.properties - ); + if (attachments.media) { + var media = $scope.parseMedia(attachments.media, attachments.type); + if (media) { + post.mediaNavs.push({ + media: media, + specificulture: $rootScope.localizeSettings.lang, + image: media.fullPath, + }); } - }.bind(ctrl); - }, - ], - bindings: { - appSettings: "=", - cultures: "=", - statuses: "=", - onDelete: "&", - onUpdate: "&", - }, -}); + } -app.component("appSettingsGeneral", { - templateUrl: - "/mix-app/views/app-portal/pages/app-settings/components/general/view.html", - controller: [ - "$rootScope", - "$scope", - "CommonService", - function ($rootScope, $scope, commonService) { - var ctrl = this; - ctrl.stopApplication = async function () { - $rootScope.isBusy = true; - await commonService.stopApplication(); + if (attachments.subattachments) { + var medias = $scope.parseMedias(attachments.subattachments.data); + angular.forEach(medias, function (e, i) { + post.mediaNavs.push({ + media: e, + specificulture: $rootScope.localizeSettings.lang, + image: e.fullPath, + }); + }); + } + return post; + }; + $scope.parseMedias = function (data) { + var result = []; + if (data) { + angular.forEach(data, function (e, i) { + var media = $scope.parseMedia(e.media, e.type); + if (media) { + result.push(media); + } + }); + } + return result; + }; + $scope.parseMedia = function (media, type) { + if (media) { + var src = ""; + switch (type) { + case "video_autoplay": + src = media.source; + break; + case "profile_media": + case "photo": + default: + src = media.image.src; + break; + } + try { + if (src) { + var index = src.lastIndexOf("/"); + var ext = src.match(/.(?:jpg|gif|png|gif|jpeg|mp4)/)[0]; + // if valid file + if (ext) { + var eIndex = src.indexOf(ext); + var filename = src.substring(index + 1, eIndex); + var media = { + fileName: filename, + fileFolder: "Facebook", + extension: ext, + targetUrl: src, + fullPath: src, + fileType: type, + source: "Facebook", + }; + + return media; + } else { + return null; + } + } else { + return null; + } + } catch (err) { + console.log("Cannot parse media", media); + return null; + } + } + }; + $scope.syncPosts = async function () { + $rootScope.isBusy = true; + var resp = await postService.saveList($scope.socialSettings.posts); + if (resp && resp.isSucceed) { $rootScope.showMessage("success", "success"); $rootScope.isBusy = false; $scope.$apply(); - }; - }, - ], - bindings: { - appSettings: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - -app.component("appSettingsHeart", { - templateUrl: - "/mix-app/views/app-portal/pages/app-settings/components/heart/view.html", - bindings: { - appSettings: "=", - }, - controller: [ - "$rootScope", - "$scope", - "CommonService", - "ngAppSettings", - function ($rootScope, $scope, commonService, ngAppSettings) { - var ctrl = this; - ctrl.$onInit = function () { - ctrl.databaseProviders = ngAppSettings.enums.database_providers; - ctrl.cacheModes = ngAppSettings.enums.cache_modes; - }; - ctrl.clearCache = async function () { - $rootScope.isBusy = true; - await commonService.clearCache(); - $rootScope.showMessage("success", "success"); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } $rootScope.isBusy = false; $scope.$apply(); - }; - }, - ], -}); - -modules.component("portalMenus", { - templateUrl: - "/mix-app/views/app-portal/pages/app-settings/components/portal-menus/view.html", - bindings: { - data: "=", - allowedTypes: "=", + } + }; }, - controller: [ - "$rootScope", - "$scope", - "$location", - "ApiService", - "CommonService", - "ngAppSettings", - function ( - $rootScope, +]); + +"use strict"; +app.controller("TemplateController", [ + "$scope", + "$rootScope", + "$routeParams", + "$location", + "ngAppSettings", + "AuthService", + "TemplateService", + function ( + $scope, + $rootScope, + $routeParams, + $location, + ngAppSettings, + authService, + service + ) { + BaseRestCtrl.call( + this, $scope, + $rootScope, $location, - apiService, - commonService, - ngAppSettings - ) { - var ctrl = this; - // ctrl.icons = []; - ctrl.translate = $rootScope.translate; - ctrl.init = function () { - ctrl.icons = ngAppSettings.icons; - }; - }, - ], -}); - -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", - controller: [ - "ngAppSettings", - function (ngAppSettings) { - var ctrl = this; - }, - ], - bindings: { - appSettings: "=", - }, -}); - -app.component("customerOrders", { - 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.isSucceed) { - $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("mixDatabaseMain", { - templateUrl: - "/mix-app/views/app-portal/pages/mix-database/components/main/view.html", - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.isInRole = $rootScope.isInRole; - ctrl.gennerateName = function () { - if ( - !ctrl.model.id || - ctrl.model.name === null || - ctrl.model.name === "" - ) { - ctrl.model.name = $rootScope.generateKeyword( - ctrl.model.title, - "_", - true, - true - ); - } - }; - }, - ], - bindings: { - model: "=", + $routeParams, + ngAppSettings, + service + ); + BaseHub.call(this, $scope); + $scope.folderTypes = [ + "Masters", + "Layouts", + "Pages", + "Modules", + "Forms", + "Edms", + "Products", + "Posts", + "Widgets", + ]; + $scope.isInitHub = false; + $scope.room = null; + $scope.members = []; + $scope.activedPane = null; + $scope.canRename = true; + $scope.user = null; + $scope.selectPane = function (pane) { + $scope.activedPane = pane; + }; + $scope.init = async function () { + authService.fillAuthData().then(function () { + $scope.user = { + username: authService.authentication.info.username, + avatar: authService.authentication.info.userData.avatar, + }; + $scope.startConnection("editFileHub", () => { + let id = $routeParams.id || $rootScope.generateUUID(); + $scope.room = `Template-${id}`; + $scope.joinRoom(); + }); + }); + }; + $scope.loadFolder = function (d) { + $location.url( + "/portal/template/list/" + + $routeParams.themeId + + "?folderType=" + + encodeURIComponent(d) + ); + }; + $scope.loadParams = async function () { + $rootScope.isBusy = true; + $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; + $scope.themeId = $routeParams.themeId; + }; + $scope.getSingle = async function () { + $rootScope.isBusy = true; + var id = $routeParams.id; + $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; + var themeId = $routeParams.themeId; + $scope.listUrl = + "/portal/template/list/" + + themeId + + "?folderType=" + + encodeURIComponent($scope.folderType); + if (id) { + var resp = await service.getSingle([id], { + folderType: $scope.folderType, + themeId: themeId, + }); + if (resp && resp.isSucceed) { + $scope.viewmodel = resp.data; + $scope.canRename = + $scope.viewmodel.id === 0 || + $scope.viewmodel.fileName.indexOf("Copy") === 0; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + } else { + var resp = await service.getDefault(); + if (resp && resp.isSucceed) { + resp.data.themeId = themeId; + resp.data.folderType = $scope.folderType; + $scope.viewmodel = resp.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + } + }; + $scope.copy = async function (id) { + $rootScope.isBusy = true; + $scope.folderType = $routeParams.folderType; // ? $routeParams.folderType : 'Masters'; + var themeId = $routeParams.themeId; + $scope.listUrl = + "/portal/template/list/" + + themeId + + "?folderType=" + + encodeURIComponent($scope.folderType); + var resp = await service.copy(id); + if (resp && resp.isSucceed) { + $location.url( + `/portal/template/details/${themeId}/${$scope.folderType}/${resp.data.id}` + ); + $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.isSucceed) { + $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.selectedExport = { + isIncludeAssets: true, + isIncludeTemplates: true, + isIncludeConfigurations: true, + isIncludePermissions: true, + pages: [], + modules: [], + mixDatabases: [], + }; + + $scope.getSingleSuccessCallback = function () { + $scope.assets = null; + $scope.theme = null; + }; + $scope.save = async function (viewmodel) { + var form = document.getElementById("form-portal"); + var frm = new FormData(); + var url = service.prefixUrl + "/save"; + + $rootScope.isBusy = true; + // Looping over all files and add it to FormData object + frm.append("assets", form["assets"].files[0]); + frm.append("theme", form["theme"].files[0]); + // Adding one more key to FormData object + frm.append("model", angular.toJson(viewmodel || $scope.viewmodel)); + + var response = await service.ajaxSubmitForm(frm, url); + if (response.isSucceed) { + $scope.viewmodel = response.data; + $rootScope.isBusy = false; + $location.url($scope.referrerUrl); + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.syncTemplates = async function (id) { + $rootScope.isBusy = true; + var response = await service.syncTemplates(id); + if (response.isSucceed) { + $scope.viewmodel = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.export = async function () { + var id = $routeParams.id; + $rootScope.isBusy = true; + var response = await service.export(id, $scope.selectedExport); + if (response.isSucceed) { + $rootScope.isBusy = false; + window.open(response.data, "_blank"); + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + $scope.saveSuccessCallback = function () { + commonService.initAllSettings().then(function () { + $location.path("/portal/theme/list"); + $rootScope.isBusy = false; + $scope.$apply(); + }); + }; + $scope.removeCallback = function () { + commonService.initAllSettings().then(function () { + $location.path("/portal/theme/list"); + }); + }; + + $scope.getExportData = async function () { + var id = $routeParams.id; + var resp = await service.getExportData(id); + if (resp && resp.isSucceed) { + $scope.exportData = resp.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.generateSEO = function () { + $scope.viewmodel.name = $rootScope.generateKeyword( + $scope.viewmodel.title, + "-" + ); + }; + }, +]); + +"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.localizeSettings = $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.isSucceed) { + $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.isSucceed) { + if ($scope.removeCallback) { + $rootScope.executeFunctionByName( + "removeCallback", + $scope.removeCallbackArgs, + $scope + ); + } + $scope.getList(); + } else { + $rootScope.showMessage("failed"); + $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.isSucceed) { + $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", + "BaseService", + function ($rootScope, apiService, commonService, baseService) { + var serviceFactory = Object.create(baseService); + serviceFactory.init("url-alias"); + + var _updateInfos = async function (pages) { + var req = { + method: "POST", + url: this.prefixUrl + "/update-infos", + data: JSON.stringify(pages), + }; + return await apiService.getApiResult(req); + }; + serviceFactory.updateInfos = _updateInfos; + return serviceFactory; + }, +]); + +"use strict"; +app.controller("UserController", [ + "$scope", + "$rootScope", + "ngAppSettings", + "$routeParams", + "$timeout", + "$location", + "AuthService", + "UserServices", + "RestMixDatabaseDataPortalService", + function ( + $scope, + $rootScope, + ngAppSettings, + $routeParams, + $timeout, + $location, + authService, + userServices, + dataService + ) { + $scope.request = { + pageSize: "10", + pageIndex: 0, + status: "Published", + orderBy: "CreatedDateTime", + direction: "Desc", + fromDate: null, + toDate: null, + keyword: "", + }; + + $scope.mediaFile = { + file: null, + fullPath: "", + folder: "User", + title: "", + description: "", + }; + $scope.activedUser = null; + $scope.relatedUsers = []; + $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.loadUser = async function () { + $rootScope.isBusy = true; + var id = $routeParams.id; + var response = await userServices.getUser(id, "portal"); + if (response.isSucceed) { + $scope.activedUser = response.data; + $rootScope.isBusy = false; + if (!$rootScope.isInRole("SuperAdmin")) { + $scope.activedUser.userRoles = $scope.activedUser.userRoles.filter( + (role) => role.description != "SuperAdmin" + ); + } + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.loadMyProfile = async function () { + $rootScope.isBusy = true; + var response = await userServices.getMyProfile(); + if (response.isSucceed) { + $scope.activedUser = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.loadUsers = async function (pageIndex) { + authService.fillAuthData().then(() => { + if ($rootScope.isInRoles(["SuperAdmin", "Admin"])) { + $scope.createUrl = "/portal/user/create"; + } + }); + + if (pageIndex !== undefined) { + $scope.request.pageIndex = pageIndex; + } + $rootScope.isBusy = true; + var resp = await userServices.getUsers($scope.request); + if (resp && resp.isSucceed) { + $scope.data = resp.data; + if (!$rootScope.isInRole("SuperAdmin")) { + $scope.data.items = $scope.data.items.filter( + (user) => + user.userRoles.length == 0 || + user.userRoles[0].role.name != "SuperAdmin" + ); + } + $.each($scope.data.items, function (i, user) { + $.each($scope.data, function (i, e) { + if (e.userId === user.id) { + user.isHidden = true; + } + }); + }); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.removeUser = function (id) { + $rootScope.showConfirm( + $scope, + "removeUserConfirmed", + [id], + null, + "Remove User", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + + $scope.removeUserConfirmed = async function (id) { + $rootScope.isBusy = true; + var result = await userServices.removeUser(id); + if (result.isSucceed) { + $scope.loadUsers(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.save = async function () { + //if (user.avatar !== user.avatarUrl) { + // user.avatar = user.avatarUrl; + //} + $rootScope.isBusy = true; + var resp = await userServices.saveUser($scope.activedUser); + if (resp && resp.isSucceed) { + $rootScope.showMessage("Update successfully!", "success"); + if ($scope.activedUser.user.id == authService.authentication.info.id) { + authService + .refreshToken( + authService.authentication.refresh_token, + authService.authentication.access_token + ) + .then(() => { + window.location = window.location; + }); + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.saveUserData = async function () { + if ($scope.activedUser.userData) { + $scope.activedUser.userData.parentId = $scope.activedUser.id; + $scope.activedUser.userData.parentType = "User"; + await dataService.save($scope.activedUser.userData); + } + }; + + $scope.register = async function (user) { + $rootScope.isBusy = true; + var resp = await userServices.register(user); + if (resp && resp.isSucceed) { + $scope.activedUser = resp.data; + $rootScope.showMessage("Update successfully!", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + $scope.updateRoleStatus = async function (nav) { + var userRole = { + userId: nav.userId, + roleId: nav.roleId, + roleName: nav.description, + isUserInRole: nav.isActived, + }; + $rootScope.isBusy = true; + var resp = await userServices.updateRoleStatus(userRole); + if (resp && resp.isSucceed) { + $rootScope.showMessage("Update successfully!", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }; }, -}); +]); -app.component("moduleMain", { - templateUrl: - "/mix-app/views/app-portal/pages/module/components/main/main.html", - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.isInRole = $rootScope.isInRole; - ctrl.gennerateName = function () { - if ( - !ctrl.module.id || - ctrl.module.name === null || - ctrl.module.name === "" - ) { - ctrl.module.name = $rootScope.generateKeyword(ctrl.module.title, "_"); +"use strict"; +app.factory("UserServices", [ + "ApiService", + "ngAppSettings", + function (apiService, ngAuthSettings) { + var usersServiceFactory = {}; + var apiUrl = "/account/"; + + var serviceBase = ngAuthSettings.serviceBase; + + var _getUserDemographicInfo = function () { + var url = "/GetUserDemographicInfo"; + var req = { + method: "GET", + url: serviceBase + url, + }; + + return apiService.getApiResult(req); + }; + + var _importUsers = function (strBase64) { + var url = "import-users"; + var req = { + method: "POST", + url: apiUrl + url, + data: JSON.stringify({ strBase64: strBase64 }), + }; + + return apiService.getApiResult(req); + }; + + var _getUsers = function (request) { + var req = { + method: "POST", + url: apiUrl + "list", + data: request, + }; + + return apiService.getApiResult(req); + }; + + var _getUser = async function (id, viewType) { + var apiUrl = "/account/"; + var url = apiUrl + "details/" + viewType; + if (id) { + url += "/" + id; + } + var req = { + method: "GET", + url: url, + }; + return await apiService.getApiResult(req); + }; + + var _getMyProfile = async function () { + var apiUrl = "/account/"; + var url = apiUrl + "my-profile"; + var req = { + method: "GET", + url: url, + }; + return await apiService.getApiResult(req); + }; + + var _updateRoleStatus = function (userInRole) { + var req = { + method: "POST", + url: serviceBase + "/account/user-in-role", + data: JSON.stringify(userInRole), + }; + + return apiService.getApiResult(req); + }; + + var _saveUser = async function (user) { + var apiUrl = "/account/"; + var req = { + method: "POST", + url: apiUrl + "save", + data: JSON.stringify(user), + }; + return await apiService.getApiResult(req); + }; + + var _register = async function (user) { + var apiUrl = "/account/"; + var req = { + method: "POST", + url: apiUrl + "register", + data: JSON.stringify(user), + }; + return await apiService.getApiResult(req); + }; + + var _removeUser = function (userId) { + var req = { + method: "GET", + url: apiUrl + "remove-user/" + userId, + }; + + return apiService.getApiResult(req); + }; + + usersServiceFactory.importUsers = _importUsers; + usersServiceFactory.getUsers = _getUsers; + usersServiceFactory.getUser = _getUser; + usersServiceFactory.getMyProfile = _getMyProfile; + usersServiceFactory.saveUser = _saveUser; + usersServiceFactory.register = _register; + usersServiceFactory.removeUser = _removeUser; + usersServiceFactory.updateRoleStatus = _updateRoleStatus; + usersServiceFactory.getUserDemographicInfo = _getUserDemographicInfo; + return usersServiceFactory; + }, +]); + +"use strict"; +function PageDetailsController($scope, $element, $attrs) { + var ctrl = this; + ctrl.activedPage = null; + ctrl.relatedPages = []; + ctrl.data = []; + ctrl.errors = []; + ctrl.range = function (max) { + var input = []; + for (var i = 1; i <= max; i += 1) input.push(i); + return input; + }; + ctrl.loadPage = function (pageId) { + ctrl.isBusy = true; + var url = "/" + ctrl.currentLanguage + "/page/details/be/" + pageId; //byPage/' + pageId; + ctrl.localizeSettings.method = "GET"; + ctrl.localizeSettings.url = url; // + '/true'; + ctrl.localizeSettings.data = ctrl.request; + $.ajax(ctrl.localizeSettings).done(function (response) { + if (response.isSucceed) { + ctrl.activedPage = response.data; + ctrl.initEditor(); + } + ctrl.isBusy = false; + ctrl.$apply(); + }); + }; + ctrl.loadPages = function (pageIndex) { + ctrl.isBusy = true; + if (pageIndex !== undefined) { + ctrl.request.pageIndex = pageIndex; + } + if (ctrl.request.fromDate !== null) { + ctrl.request.fromDate = ctrl.request.fromDate.toISOString(); + } + if (ctrl.request.toDate !== null) { + ctrl.request.toDate = ctrl.request.toDate.toISOString(); + } + var url = "/" + ctrl.currentLanguage + "/page/list"; //byPage/' + pageId; + ctrl.localizeSettings.method = "POST"; + ctrl.localizeSettings.url = url; // + '/true'; + ctrl.localizeSettings.data = ctrl.request; + $.ajax(ctrl.localizeSettings).done(function (response) { + ctrl.data = response.data; + + $.each(ctrl.data.items, function (i, page) { + $.each(ctrl.activedPages, function (i, e) { + if (e.pageId === page.id) { + page.isHidden = true; + } + }); + }); + ctrl.isBusy = false; + setTimeout(function () { + $('[data-bs-toggle="popover"]').popover({ + html: true, + content: function () { + var content = $(this).next(".popover-body"); + return $(content).html(); + }, + title: function () { + var title = $(this).attr("data-popover-content"); + return $(title).children(".popover-heading").html(); + }, + }); + }, 200); + ctrl.$apply(); + }); + }; + + ctrl.removePage = function (pageId) { + if (confirm("Are you sure!")) { + var url = "/" + ctrl.currentLanguage + "/page/delete/" + pageId; + $.ajax({ + method: "GET", + url: url, + success: function (data) { + ctrl.loadPages(); + ctrl.$apply(); + }, + error: function (a, b, c) {}, + }); + } + }; + ctrl.savePage = function (page) { + var url = "/" + ctrl.currentLanguage + "/page/save"; + $.ajax({ + method: "POST", + url: url, + data: page, + success: function (data) { + //ctrl.loadPages(); + if (data.isSucceed) { + alert("success"); + } else { + alert("failed! " + data.errors); } + }, + error: function (a, b, c) {}, + }); + }; + + ctrl.changeMedia = function (media) { + var currentItem = null; + if (ctrl.activedPage.mediaNavs === undefined) { + ctrl.activedPage.mediaNavs = []; + } + $.each(ctrl.activedPage.mediaNavs, function (i, e) { + if (e.mediaId === media.id) { + e.isActived = media.isActived; + currentItem = e; + return false; + } + }); + if (currentItem === null) { + currentItem = { + description: media.description !== "undefined" ? media.description : "", + image: media.fullPath, + mediaId: media.id, + page: ctrl.activedPage.id, + specificulture: media.specificulture, + position: 0, + priority: ctrl.activedMedias.length + 1, + isActived: true, }; - }, - ], - bindings: { - module: "=", - }, -}); + media.isHidden = true; + ctrl.activedPage.mediaNavs.push(currentItem); + } + }; -app.component("moduleContent", { - templateUrl: - "/mix-app/views/app-portal/pages/module/components/module-content/view.html", - bindings: { - model: "=", - additionalData: "=", - }, - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.$onInit = function () { - ctrl.backUrl = `/portal/module/details`; + ctrl.changePage = function (page) { + var currentItem = null; + $.each(ctrl.activedPage.pageNavs, function (i, e) { + if (e.relatedPageId === page.id) { + e.isActived = page.isActived; + currentItem = e; + return false; + } + }); + if (currentItem === null) { + currentItem = { + relatedPageId: page.id, + sourcePageId: $("#page-id").val(), + specificulture: page.specificulture, + priority: ctrl.activedPage.pageNavs.length + 1, + page: page, + isActived: true, }; - ctrl.localizeSettings = $rootScope.globalSettings; - }, - ], -}); + page.isHidden = true; + ctrl.activedPage.pageNavs.push(currentItem); + } + }; -app.component("mixDatabaseEdm", { + ctrl.addProperty = function (type) { + var i = $(".property").length; + $.ajax({ + method: "GET", + url: + "/" + + ctrl.currentLanguage + + "/Portal/" + + type + + "/AddEmptyProperty/" + + i, + success: function (data) { + $("#tbl-properties > tbody").append(data); + $(data).find(".prop-data-type").trigger("change"); + }, + error: function (a, b, c) {}, + }); + ctrl.updateHero = function (hero, prop, value) { + hero[prop] = value; + }; + + ctrl.deleteHero = function (hero) { + var idx = ctrl.list.indexOf(hero); + if (idx >= 0) { + ctrl.list.splice(idx, 1); + } + }; + }; + + angular.module(appName).component("pageDetails", { + templateUrl: "pageDetails.html", + controller: PageDetailsController, + }); +} + +app.component("appSettingsAuth", { templateUrl: - "/mix-app/views/app-portal/pages/mix-database/components/edm/view.html", + "/mix-app/views/app-portal/pages/app-settings/components/auth/view.html", controller: [ - "$rootScope", - function ($rootScope) { + "ngAppSettings", + function (ngAppSettings) { var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; }, ], bindings: { - model: "=", + appSettings: "=", + onDelete: "&", + onUpdate: "&", }, }); -app.component("moduleAdvanced", { +app.component("appSettingsDefault", { templateUrl: - "/mix-app/views/app-portal/pages/module/components/module-advanced/view.html", - bindings: { - model: "=", - additionalData: "=", - }, + "/mix-app/views/app-portal/pages/app-settings/components/default/view.html", controller: [ "$rootScope", - function ($rootScope) { + "ngAppSettings", + function ($rootScope, ngAppSettings) { var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; ctrl.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; - }; - }, - ], -}); - -app.component("moduleType", { - templateUrl: - "/mix-app/views/app-portal/pages/module/components/module-type/view.html", - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; - }, - ], - bindings: { - model: "=", - }, -}); - -app.component("pageGeneral", { - templateUrl: - "/mix-app/views/app-portal/pages/page/components/general/general.html", - controller: function ($rootScope) { - var ctrl = this; - ctrl.isInRole = $rootScope.isInRole; - ctrl.dataTypes = [ - { - title: "String", - value: "text", - }, - { - title: "Int", - value: "int", - }, - { - title: "Image", - value: "image", - }, - { - title: "Boolean", - value: "boolean", - }, - ]; - ctrl.configurations = { - core: {}, - plugins: { - btnsDef: { - // Customizables dropdowns - image: { - dropdown: ["insertImage", "upload", "base64", "noembed"], - ico: "insertImage", - }, - }, - btns: [ - ["viewHTML"], - ["undo", "redo"], - ["formatting"], - ["strong", "em", "del", "underline"], - ["link"], - ["image"], - ["justifyLeft", "justifyCenter", "justifyRight", "justifyFull"], - ["unorderedList", "orderedList"], - ["foreColor", "backColor"], - ["preformatted"], - ["horizontalRule"], - ["fullscreen"], - ], - plugins: { - // Add imagur parameters to upload plugin - upload: { - serverPath: "https://api.imgur.com/3/image", - fileFieldName: "image", - headers: { - Authorization: "Client-ID 9e57cb1c4791cea", - }, - urlPropertyName: "data.link", - }, - }, - }, - }; - ctrl.addProperty = function (type) { - var i = $(".property").length; - ctrl.page.properties.push({ - priority: 0, - name: "", - value: null, - dataType: 0, - }); - }; - ctrl.initEditor = function () { - setTimeout(function () { - // Init Code editor - $.each($(".code-editor"), function (i, e) { - var container = $(this); - var editor = ace.edit(e); - if (container.hasClass("json")) { - editor.session.setMode("ace/mode/json"); - } else { - editor.session.setMode("ace/mode/razor"); - } - editor.setTheme("ace/theme/chrome"); - //editor.setReadOnly(true); - - editor.session.setUseWrapMode(true); - editor.setOptions({ - maxLines: Infinity, - }); - editor.getSession().on("change", function (e) { - // e.type, etc - $(container).parent().find(".code-content").val(editor.getValue()); - }); - }); - $.each($(".editor-content"), function (i, e) { - var $demoTextarea = $(e); - $demoTextarea.quill(ctrl.configurations.plugins); + ctrl.properties = $.parseJSON( + ctrl.appSettings.GlobalSettings.DefaultPostAttr + ); + ctrl.trackedProperties = $.parseJSON( + ctrl.appSettings.GlobalSettings.DefaultPostAttr + ); + ctrl.dataTypes = $rootScope.globalSettings.dataTypes; + }; + ctrl.addPostProperty = function () { + ctrl.properties.push({ + priority: 0, + name: "", + value: null, + dataType: "7", }); - }, 200); - }; - }, + }; + ctrl.$doCheck = function () { + if (ctrl.trackedProperties != ctrl.properties) { + ctrl.trackedProperties = angular.copy(ctrl.properties); + ctrl.appSettings.GlobalSettings.DefaultPostAttr = JSON.stringify( + ctrl.properties + ); + } + }.bind(ctrl); + }, + ], bindings: { - page: "=", + appSettings: "=", + cultures: "=", + statuses: "=", onDelete: "&", onUpdate: "&", }, }); -app.component("pageMain", { - templateUrl: "/mix-app/views/app-portal/pages/page/components/main/main.html", +app.component("appSettingsGeneral", { + templateUrl: + "/mix-app/views/app-portal/pages/app-settings/components/general/view.html", controller: [ "$rootScope", "$scope", - "ngAppSettings", - function ($rootScope, $scope) { + "CommonService", + function ($rootScope, $scope, commonService) { var ctrl = this; - ctrl.localizeSettings = $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; - } - } + ctrl.stopApplication = async function () { + $rootScope.isBusy = true; + await commonService.stopApplication(); + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); }; }, ], bindings: { - page: "=", + appSettings: "=", onDelete: "&", onUpdate: "&", }, }); -app.component("pageModules", { +app.component("appSettingsHeart", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/modules/modules.html", + "/mix-app/views/app-portal/pages/app-settings/components/heart/view.html", bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", + appSettings: "=", }, + controller: [ + "$rootScope", + "$scope", + "CommonService", + "ngAppSettings", + function ($rootScope, $scope, commonService, ngAppSettings) { + var ctrl = this; + ctrl.$onInit = function () { + ctrl.databaseProviders = ngAppSettings.enums.database_providers; + ctrl.cacheModes = ngAppSettings.enums.cache_modes; + }; + ctrl.clearCache = async function () { + $rootScope.isBusy = true; + await commonService.clearCache(); + $rootScope.showMessage("success", "success"); + $rootScope.isBusy = false; + $scope.$apply(); + }; + }, + ], }); -app.component("pageAdvanced", { +modules.component("portalMenus", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/page-advanced/view.html", + "/mix-app/views/app-portal/pages/app-settings/components/portal-menus/view.html", bindings: { - model: "=", - additionalData: "=", + data: "=", + allowedTypes: "=", }, controller: [ "$rootScope", "$scope", - function ($rootScope, $scope) { + "$location", + "ApiService", + "CommonService", + "ngAppSettings", + function ( + $rootScope, + $scope, + $location, + apiService, + commonService, + ngAppSettings + ) { var ctrl = this; - + // ctrl.icons = []; ctrl.translate = $rootScope.translate; - ctrl.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; + ctrl.init = function () { + ctrl.icons = ngAppSettings.icons; }; }, ], }); -app.component("pageContent", { +app.component("appSettingsSmtp", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/page-content/view.html", + "/mix-app/views/app-portal/pages/app-settings/components/smtp/view.html", + controller: [ + "ngAppSettings", + function (ngAppSettings) { + var ctrl = this; + }, + ], bindings: { - model: "=", - additionalData: "=", + appSettings: "=", }, +}); + +app.component("customerOrders", { + templateUrl: + "/mix-app/views/app-portal/pages/customer/components/orders/customer-orders.html", controller: [ "$rootScope", - "$scope", - function ($rootScope, $scope) { + "OrderServices", + function ($rootScope, orderServices) { var ctrl = this; - ctrl.translate = $rootScope.translate; - ctrl.$onInit = function () { - ctrl.backUrl = `/portal/page/details`; + 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.generateSeo = function () { - if ($scope.viewmodel) { - if (ctrl.model.seoName === null || ctrl.model.seoName === "") { - ctrl.model.seoName = $rootScope.generateKeyword( - ctrl.model.title, - "-" - ); - } - if (ctrl.model.seoTitle === null || ctrl.model.seoTitle === "") { - ctrl.model.seoTitle = ctrl.model.title; - } - if ( - ctrl.model.seoDescription === null || - ctrl.model.seoDescription === "" - ) { - ctrl.model.seoDescription = ctrl.model.excerpt; - } - if ( - ctrl.model.seoKeywords === null || - ctrl.model.seoKeywords === "" - ) { - ctrl.model.seoKeywords = ctrl.model.title; - } + + ctrl.removeOrderConfirmed = async function (id) { + var result = await orderServices.removeOrder(id); + if (result.isSucceed) { + $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("pageParents", { +app.component("customerMain", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/parents/parents.html", + "/mix-app/views/app-portal/pages/customer/components/main/customer-main.html", bindings: { - page: "=", + customer: "=", onDelete: "&", onUpdate: "&", }, }); -app.component("pageType", { +app.component("mixDatabaseEdm", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/page-type/view.html", - bindings: { - model: "=", - }, + "/mix-app/views/app-portal/pages/mix-database/components/edm/view.html", controller: [ "$rootScope", function ($rootScope) { @@ -7065,353 +6707,272 @@ app.component("pageType", { ctrl.localizeSettings = $rootScope.globalSettings; }, ], + bindings: { + model: "=", + }, }); -app.component("pagePlugPlay", { +app.component("mixDatabaseMain", { templateUrl: - "/mix-app/views/app-portal/pages/page/components/plug-play/plug-play.html", + "/mix-app/views/app-portal/pages/mix-database/components/main/view.html", + controller: [ + "$rootScope", + function ($rootScope) { + var ctrl = this; + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.isInRole = $rootScope.isInRole; + ctrl.gennerateName = function () { + if ( + !ctrl.model.id || + ctrl.model.name === null || + ctrl.model.name === "" + ) { + ctrl.model.name = $rootScope.generateKeyword( + ctrl.model.title, + "_", + true, + true + ); + } + }; + }, + ], bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", + model: "=", }, }); -app.component("pageSeo", { - templateUrl: "/mix-app/views/app-portal/pages/page/components/seo/seo.html", +app.component("moduleMain", { + templateUrl: + "/mix-app/views/app-portal/pages/module/components/main/main.html", controller: [ "$rootScope", function ($rootScope) { var ctrl = this; - ctrl.translate = function (keyword) { - return $rootScope.translate(keyword); + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.isInRole = $rootScope.isInRole; + ctrl.gennerateName = function () { + if ( + !ctrl.module.id || + ctrl.module.name === null || + ctrl.module.name === "" + ) { + ctrl.module.name = $rootScope.generateKeyword(ctrl.module.title, "_"); + } }; }, ], bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", + module: "=", }, }); -modules.component("postFilterList", { +app.component("moduleAdvanced", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/filter-list/filter-list.html", + "/mix-app/views/app-portal/pages/module/components/module-advanced/view.html", bindings: { - request: "=", - key: "=?", - orders: "=?", - createUrl: "=", - createText: "=", - categories: "=", - postTypes: "=", - callback: "&", + model: "=", + additionalData: "=", }, controller: [ - "$scope", "$rootScope", - "ngAppSettings", - "RestMixDatabaseDataPortalService", - function ($scope, $rootScope, ngAppSettings, dataService) { + function ($rootScope) { var ctrl = this; - ctrl.dateRange = { - fromDate: null, - toDate: null, - }; - ctrl.request = angular.copy(ngAppSettings.request); - - ctrl.init = function () { - if (!ctrl.orders) { - ctrl.orders = ngAppSettings.orders; - } - ctrl.directions = ngAppSettings.directions; - ctrl.pageSizes = ngAppSettings.pageSizes; - ctrl.statuses = []; - var statuses = ngAppSettings.contentStatuses; - if (ctrl.request && ctrl.request.contentStatuses) { - statuses = ctrl.request.contentStatuses; - } - angular.forEach(statuses, function (val, i) { - ctrl.statuses.push({ - value: val, - title: val, - }); - }); - }; - - ctrl.apply = function (pageIndex) { - $rootScope.setRequest(ctrl.request, ctrl.key); - ctrl.callback({ pageIndex: pageIndex }); - }; - ctrl.updateDate = function () { - if (Date.parse(ctrl.dateRange.fromDate)) { - ctrl.request.fromDate = new Date( - 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 }); + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; }; }, ], }); -app.component("productRelated", { - templateUrl: - "/mix-app/views/app-portal/pages/product/components/related/productRelated.html", - controller: function () { - var ctrl = this; - ctrl.activeProduct = function (pr) { - var currentItem = null; - $.each(ctrl.product.productNavs, function (i, e) { - if (e.relatedProductId === pr.id) { - e.isActived = pr.isActived; - currentItem = e; - return false; - } - }); - if (currentItem === null) { - currentItem = { - relatedProductId: pr.id, - sourceProductId: ctrl.product.id, - specificulture: ctrl.product.specificulture, - priority: ctrl.product.productNavs.length + 1, - relatedProduct: pr, - isActived: true, - }; - pr.isHidden = true; - ctrl.product.productNavs.push(currentItem); - } - }; - }, - bindings: { - product: "=", - list: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - -app.component("postGeneral", { +app.component("moduleType", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/general/view.html", + "/mix-app/views/app-portal/pages/module/components/module-type/view.html", controller: [ "$rootScope", - "ngAppSettings", - function ($rootScope, ngAppSettings) { + function ($rootScope) { var ctrl = this; - ctrl.dataTypes = $rootScope.globalSettings.dataTypes; - ctrl.$onInit = function () {}; - ctrl.addProperty = function (type) { - var i = $(".property").length; - ctrl.post.properties.push({ - title: "", - name: "", - value: null, - dataType: "text", - }); - }; + ctrl.localizeSettings = $rootScope.globalSettings; }, ], bindings: { - post: "=", - isAdmin: "=", - onDelete: "&", - onUpdate: "&", + model: "=", }, }); -app.component("postModules", { +app.component("moduleContent", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/modules/view.html", + "/mix-app/views/app-portal/pages/module/components/module-content/view.html", + bindings: { + model: "=", + additionalData: "=", + }, controller: [ "$rootScope", - "$scope", - "ngAppSettings", - "SharedModuleDataService", - function ($rootScope, $scope, ngAppSettings, moduleDataService) { + function ($rootScope) { var ctrl = this; - ctrl.request = angular.copy(ngAppSettings.request); - ctrl.translate = function (keyword, wrap, defaultValue) { - return $rootScope.translate(keyword, wrap, defaultValue); + ctrl.$onInit = function () { + ctrl.backUrl = `/portal/module/details`; }; + ctrl.localizeSettings = $rootScope.globalSettings; + }, + ], +}); - ctrl.removeData = function (id, moduleId) { - $rootScope.showConfirm( - ctrl, - "removeDataConfirmed", - [id, moduleId], - null, - "Remove Data", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - ctrl.removeDataConfirmed = async function (id, moduleId) { - $rootScope.isBusy = true; - var result = await moduleDataService.removeModuleData(id); - if (result.isSucceed) { - ctrl.loadModuleDatas(moduleId); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - ctrl.saveDataCallback = function (data) { - if (data) { - ctrl.loadModuleDatas(data.moduleId); - } - }; - ctrl.loadModuleDatas = async function (id, pageIndex) { - $rootScope.isBusy = true; - $scope.dataColumns = []; - var request = angular.copy(ngAppSettings.request); - request.query = "?module_id=" + id + "&post_id=" + ctrl.post.id; - if (pageIndex) { - request.pageIndex = pageIndex; - } - var response = await moduleDataService.getModuleDatas(request); - if (response.isSucceed) { - var nav = $rootScope.findObjectByKey( - ctrl.post.moduleNavs, - "moduleId", - id - ); - if (nav) { - nav.module.data = response.data; +app.component("pageGeneral", { + templateUrl: + "/mix-app/views/app-portal/pages/page/components/general/general.html", + controller: function ($rootScope) { + var ctrl = this; + ctrl.isInRole = $rootScope.isInRole; + ctrl.dataTypes = [ + { + title: "String", + value: "text", + }, + { + title: "Int", + value: "int", + }, + { + title: "Image", + value: "image", + }, + { + title: "Boolean", + value: "boolean", + }, + ]; + ctrl.configurations = { + core: {}, + plugins: { + btnsDef: { + // Customizables dropdowns + image: { + dropdown: ["insertImage", "upload", "base64", "noembed"], + ico: "insertImage", + }, + }, + btns: [ + ["viewHTML"], + ["undo", "redo"], + ["formatting"], + ["strong", "em", "del", "underline"], + ["link"], + ["image"], + ["justifyLeft", "justifyCenter", "justifyRight", "justifyFull"], + ["unorderedList", "orderedList"], + ["foreColor", "backColor"], + ["preformatted"], + ["horizontalRule"], + ["fullscreen"], + ], + plugins: { + // Add imagur parameters to upload plugin + upload: { + serverPath: "https://api.imgur.com/3/image", + fileFieldName: "image", + headers: { + Authorization: "Client-ID 9e57cb1c4791cea", + }, + urlPropertyName: "data.link", + }, + }, + }, + }; + ctrl.addProperty = function (type) { + var i = $(".property").length; + ctrl.page.properties.push({ + priority: 0, + name: "", + value: null, + dataType: 0, + }); + }; + ctrl.initEditor = function () { + setTimeout(function () { + // Init Code editor + $.each($(".code-editor"), function (i, e) { + var container = $(this); + var editor = ace.edit(e); + if (container.hasClass("json")) { + editor.session.setMode("ace/mode/json"); + } else { + editor.session.setMode("ace/mode/razor"); } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; + editor.setTheme("ace/theme/chrome"); + //editor.setReadOnly(true); - ctrl.updateDataInfos = async function (items) { - $rootScope.isBusy = true; - var resp = await moduleDataService.updateInfos(items); - if (resp && resp.isSucceed) { - $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(); - } - }; - }, - ], + editor.session.setUseWrapMode(true); + editor.setOptions({ + maxLines: Infinity, + }); + editor.getSession().on("change", function (e) { + // e.type, etc + $(container).parent().find(".code-content").val(editor.getValue()); + }); + }); + $.each($(".editor-content"), function (i, e) { + var $demoTextarea = $(e); + $demoTextarea.quill(ctrl.configurations.plugins); + }); + }, 200); + }; + }, bindings: { - post: "=", + page: "=", onDelete: "&", onUpdate: "&", }, }); -app.component("postMain", { - templateUrl: "/mix-app/views/app-portal/pages/post/components/main/view.html", - bindings: { - post: "=", - }, +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.translate = $rootScope.translate; + ctrl.localizeSettings = $rootScope.globalSettings; + // ctrl.setPageType = function (type) { + // ctrl.page.type = $index; + // } ctrl.generateSeo = function () { - if (ctrl.post) { - if (!ctrl.post.seoName) { - ctrl.post.seoName = $rootScope.generateKeyword( - ctrl.post.title, + if (ctrl.page) { + if (ctrl.page.seoName === null || ctrl.page.seoName === "") { + ctrl.page.seoName = $rootScope.generateKeyword( + ctrl.page.title, "-" ); } - if (!ctrl.post.seoTitle) { - ctrl.post.seoTitle = ctrl.post.title; + if (ctrl.page.seoTitle === null || ctrl.page.seoTitle === "") { + ctrl.page.seoTitle = ctrl.page.title; } - if (!ctrl.post.seoDescription === null) { - ctrl.post.seoDescription = ctrl.post.excerpt; + if ( + ctrl.page.seoDescription === null || + ctrl.page.seoDescription === "" + ) { + ctrl.page.seoDescription = ctrl.page.excerpt; } - if (!ctrl.post.seoKeywords) { - ctrl.post.seoKeywords = ctrl.post.title; + if (ctrl.page.seoKeywords === null || ctrl.page.seoKeywords === "") { + ctrl.page.seoKeywords = ctrl.page.title; } } }; }, ], -}); - -app.component("postParents", { - templateUrl: - "/mix-app/views/app-portal/pages/post/components/parents/view.html", - bindings: { - post: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - -app.component("postMedias", { - templateUrl: - "/mix-app/views/app-portal/pages/post/components/medias/view.html", - controller: function () { - var ctrl = this; - ctrl.activeMedia = function (media) { - var currentItem = null; - if (ctrl.post.mediaNavs === null) { - ctrl.post.mediaNavs = []; - } - $.each(ctrl.post.mediaNavs, function (i, e) { - if (e.mediaId === media.id) { - e.isActived = media.isActived; - currentItem = e; - return false; - } - }); - if (currentItem === null) { - currentItem = { - description: - media.description !== "undefined" ? media.description : "", - image: media.filePath, - mediaId: media.id, - post: ctrl.post.id, - specificulture: media.specificulture, - position: 0, - priority: ctrl.post.mediaNavs.length + 1, - isActived: true, - }; - media.isHidden = true; - ctrl.post.mediaNavs.push(currentItem); - } - }; - }, bindings: { - post: "=", - medias: "=", - loadMedia: "&", + page: "=", onDelete: "&", onUpdate: "&", }, }); -app.component("postAdvanced", { +app.component("pageAdvanced", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/post-advanced/view.html", + "/mix-app/views/app-portal/pages/page/components/page-advanced/view.html", bindings: { model: "=", additionalData: "=", @@ -7421,6 +6982,7 @@ app.component("postAdvanced", { "$scope", function ($rootScope, $scope) { var ctrl = this; + ctrl.translate = $rootScope.translate; ctrl.$onInit = function () { ctrl.isAdmin = $rootScope.isAdmin; @@ -7429,9 +6991,19 @@ app.component("postAdvanced", { ], }); -app.component("postContent", { +app.component("pageModules", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/post-content/view.html", + "/mix-app/views/app-portal/pages/page/components/modules/modules.html", + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + +app.component("pageContent", { + templateUrl: + "/mix-app/views/app-portal/pages/page/components/page-content/view.html", bindings: { model: "=", additionalData: "=", @@ -7439,150 +7011,125 @@ app.component("postContent", { controller: [ "$rootScope", "$scope", - "ngAppSettings", - "PostRestService", - function ($rootScope, $scope, ngAppSettings, service) { - var ctrl = this; - ctrl.request = angular.copy(ngAppSettings.request); - ctrl.translate = $rootScope.translate; - ctrl.relatedData = {}; - ctrl.$onInit = function () { - ctrl.backUrl = `/portal/post/details`; - }; - ctrl.generateSeo = function () { - if (ctrl.model) { - if (ctrl.model.seoName === null || ctrl.model.seoName === "") { - ctrl.model.seoName = $rootScope.generateKeyword( - ctrl.model.title, - "-" - ); - } - if (ctrl.model.seoTitle === null || ctrl.model.seoTitle === "") { - ctrl.model.seoTitle = ctrl.model.title; - } - if ( - ctrl.model.seoDescription === null || - ctrl.model.seoDescription === "" - ) { - ctrl.model.seoDescription = ctrl.model.excerpt; - } - if ( - ctrl.model.seoKeywords === null || - ctrl.model.seoKeywords === "" - ) { - ctrl.model.seoKeywords = ctrl.model.title; - } - } - }; - ctrl.getListRelated = async function (pageIndex) { - if (pageIndex !== undefined) { - ctrl.request.pageIndex = pageIndex; - } - if (ctrl.request.fromDate !== null) { - var d = new Date(ctrl.request.fromDate); - ctrl.request.fromDate = d.toISOString(); - } - if (ctrl.request.toDate !== null) { - var d = new Date(ctrl.request.toDate); - ctrl.request.toDate = d.toISOString(); - } - var resp = await service.getList(ctrl.request); - if (resp && resp.isSucceed) { - ctrl.relatedData = angular.copy(resp.data); - ctrl.relatedData.items = []; - angular.forEach(resp.data.items, (element) => { - var existed = $rootScope.findObjectByKey( - ctrl.model.postNavs, - ["sourceId", "destinationId"], - [ctrl.model.id, element.id] - ); - - var obj = { - description: element.title, - destinationId: element.id, - image: element.image, - isActived: existed !== null, - sourceId: ctrl.model.id, - specificulture: ctrl.model.specificulture, - status: "Published", - }; - - ctrl.relatedData.items.push(obj); - }); - console.log(ctrl.relatedData); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(getData.errors); - $rootScope.isBusy = false; - $scope.$apply(); + function ($rootScope, $scope) { + var ctrl = this; + ctrl.translate = $rootScope.translate; + ctrl.$onInit = function () { + ctrl.backUrl = `/portal/page/details`; + }; + ctrl.generateSeo = function () { + if ($scope.viewmodel) { + if (ctrl.model.seoName === null || ctrl.model.seoName === "") { + ctrl.model.seoName = $rootScope.generateKeyword( + ctrl.model.title, + "-" + ); + } + if (ctrl.model.seoTitle === null || ctrl.model.seoTitle === "") { + ctrl.model.seoTitle = ctrl.model.title; + } + if ( + ctrl.model.seoDescription === null || + ctrl.model.seoDescription === "" + ) { + ctrl.model.seoDescription = ctrl.model.excerpt; + } + if ( + ctrl.model.seoKeywords === null || + ctrl.model.seoKeywords === "" + ) { + ctrl.model.seoKeywords = ctrl.model.title; + } } }; }, ], }); -modules.component("relatedNavs", { +app.component("pageType", { templateUrl: - "/mix-app/views/app-portal/pages/post/components/related-navigations/view.html", + "/mix-app/views/app-portal/pages/page/components/page-type/view.html", bindings: { - request: "=", - prefix: "=", - sourceId: "=", - culture: "=", - navs: "=", - data: "=", - categories: "=", - postTypes: "=", - loadData: "&", + model: "=", }, controller: [ "$rootScope", - "$scope", - function ($rootScope, $scope) { + function ($rootScope) { var ctrl = this; - ctrl.selected = null; - ctrl.activeItem = function (item, index) { - var currentItem = $rootScope.findObjectByKey( - ctrl.navs, - ["sourceId", "destinationId"], - [ctrl.sourceId, item.id] - ); - if (currentItem === null) { - currentItem = item; - currentItem.priority = ctrl.navs.length + 1; - ctrl.navs.push(currentItem); - ctrl.data.items.splice(index, 1); - } - }; - ctrl.updateOrders = function (index) { - ctrl.navs.splice(index, 1); - for (var i = 0; i < ctrl.data.length; i++) { - ctrl.navs[i].priority = i + 1; - } - }; - ctrl.load = async function (pageIndex) { - if (pageIndex !== undefined) { - ctrl.request.pageIndex = pageIndex; - } - ctrl.data = await ctrl.loadData({ pageIndex: ctrl.request.pageIndex }); - $scope.$apply(); - }; - ctrl.checkActived = function (item) { - if (ctrl.navs) { - return ctrl.navs.find(function (nav) { - return nav.destinationId === item.id; - }); - } + ctrl.localizeSettings = $rootScope.globalSettings; + }, + ], +}); + +app.component("pageParents", { + templateUrl: + "/mix-app/views/app-portal/pages/page/components/parents/parents.html", + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + +app.component("pagePlugPlay", { + templateUrl: + "/mix-app/views/app-portal/pages/page/components/plug-play/plug-play.html", + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + +app.component("pageSeo", { + templateUrl: "/mix-app/views/app-portal/pages/page/components/seo/seo.html", + controller: [ + "$rootScope", + function ($rootScope) { + var ctrl = this; + ctrl.translate = function (keyword) { + return $rootScope.translate(keyword); }; }, ], + bindings: { + page: "=", + onDelete: "&", + onUpdate: "&", + }, }); -app.component("postSeo", { - templateUrl: "/mix-app/views/app-portal/pages/post/components/seo/view.html", +app.component("productRelated", { + templateUrl: + "/mix-app/views/app-portal/pages/product/components/related/productRelated.html", + controller: function () { + var ctrl = this; + ctrl.activeProduct = function (pr) { + var currentItem = null; + $.each(ctrl.product.productNavs, function (i, e) { + if (e.relatedProductId === pr.id) { + e.isActived = pr.isActived; + currentItem = e; + return false; + } + }); + if (currentItem === null) { + currentItem = { + relatedProductId: pr.id, + sourceProductId: ctrl.product.id, + specificulture: ctrl.product.specificulture, + priority: ctrl.product.productNavs.length + 1, + relatedProduct: pr, + isActived: true, + }; + pr.isHidden = true; + ctrl.product.productNavs.push(currentItem); + } + }; + }, bindings: { - post: "=", + product: "=", + list: "=", onDelete: "&", onUpdate: "&", }, @@ -7626,6 +7173,16 @@ 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", @@ -7725,40 +7282,6 @@ app.component("permissionPlugPlay", { ], }); -app.component("permissionParents", { - templateUrl: - "/mix-app/views/app-portal/pages/permission/components/parents/parents.html", - bindings: { - page: "=", - onDelete: "&", - onUpdate: "&", - }, -}); - -app.component("serviceMain", { - templateUrl: - "/mix-app/views/app-portal/pages/service/components/main/view.html", - controller: [ - "$rootScope", - function ($rootScope) { - var ctrl = this; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.gennerateName = function () { - if ( - !ctrl.model.id || - ctrl.model.name === null || - ctrl.model.name === "" - ) { - ctrl.model.name = $rootScope.generateKeyword(ctrl.model.title, "_"); - } - }; - }, - ], - bindings: { - model: "=", - }, -}); - modules.component("rolePageNav", { templateUrl: "/mix-app/views/app-portal/pages/role/components/role-page-navigation/role-page-navigations.html", @@ -7800,942 +7323,1030 @@ modules.component("rolePageNav", { }, }); -app.component("themeExportMixDatabases", { +modules.component("postFilterList", { templateUrl: - "/mix-app/views/app-portal/pages/theme/components/theme-export-mix-databases/view.html", + "/mix-app/views/app-portal/pages/post/components/filter-list/filter-list.html", + bindings: { + request: "=", + key: "=?", + orders: "=?", + createUrl: "=", + createText: "=", + categories: "=", + postTypes: "=", + callback: "&", + }, controller: [ - "$rootScope", "$scope", + "$rootScope", "ngAppSettings", - function ($rootScope, $scope) { + "RestMixDatabaseDataPortalService", + function ($scope, $rootScope, ngAppSettings, dataService) { var ctrl = this; - ctrl.updateMixDatabaseExport = function () { - ctrl.selectedExport.mixDatabases = angular.copy( - $rootScope.filterArray( - ctrl.exportData.mixDatabases, - ["isActived"], - [true] - ) - ); - // angular.forEach(ctrl.selectedExport.mixDatabases,function(e){ - // e.data = angular.copy($rootScope.filterArray(e.data, ['isActived'], [true])); - // }); + ctrl.dateRange = { + fromDate: null, + toDate: null, }; - ctrl.selectAll = function (arr) { - ctrl.selectedList.data = []; - angular.forEach(arr, function (e) { - e.isActived = ctrl.selectedList.isSelectAll; - e.isExportData = ctrl.selectedList.isExportData; + ctrl.request = angular.copy(ngAppSettings.request); + + ctrl.init = function () { + if (!ctrl.orders) { + ctrl.orders = ngAppSettings.orders; + } + ctrl.directions = ngAppSettings.directions; + ctrl.pageSizes = ngAppSettings.pageSizes; + ctrl.statuses = []; + var statuses = ngAppSettings.contentStatuses; + if (ctrl.request && ctrl.request.contentStatuses) { + statuses = ctrl.request.contentStatuses; + } + angular.forEach(statuses, function (val, i) { + ctrl.statuses.push({ + value: val, + title: val, + }); }); - ctrl.updateMixDatabaseExport(); + }; + + ctrl.apply = function (pageIndex) { + $rootScope.setRequest(ctrl.request, ctrl.key); + ctrl.callback({ pageIndex: pageIndex }); + }; + ctrl.updateDate = function () { + if (Date.parse(ctrl.dateRange.fromDate)) { + ctrl.request.fromDate = new Date( + 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: { - exportData: "=", - selectedExport: "=", - }, }); -app.component("themeExportModules", { +app.component("postGeneral", { templateUrl: - "/mix-app/views/app-portal/pages/theme/components/theme-export-modules/view.html", + "/mix-app/views/app-portal/pages/post/components/general/view.html", controller: [ "$rootScope", - "$scope", "ngAppSettings", - function ($rootScope, $scope) { + function ($rootScope, ngAppSettings) { var ctrl = this; - ctrl.updateModuleExport = function () { - ctrl.selectedExport.modules = angular.copy( - $rootScope.filterArray(ctrl.exportData.modules, ["isActived"], [true]) - ); - // angular.forEach(ctrl.selectedExport.modules,function(e){ - // e.data.items = angular.copy($rootScope.filterArray(e.data.items, ['isActived'], [true])); - // }); - }; - ctrl.selectAll = function (arr) { - ctrl.selectedList.data = []; - angular.forEach(arr, function (e) { - e.isActived = ctrl.selectedList.isSelectAll; - e.isExportData = ctrl.selectedList.isExportData; + ctrl.dataTypes = $rootScope.globalSettings.dataTypes; + ctrl.$onInit = function () {}; + ctrl.addProperty = function (type) { + var i = $(".property").length; + ctrl.post.properties.push({ + title: "", + name: "", + value: null, + dataType: "text", }); - ctrl.updateModuleExport(); }; }, ], bindings: { - exportData: "=", - selectedExport: "=", + post: "=", + isAdmin: "=", + onDelete: "&", + onUpdate: "&", }, }); -app.component("themeExportPages", { +app.component("postMedias", { templateUrl: - "/mix-app/views/app-portal/pages/theme/components/theme-export-pages/view.html", + "/mix-app/views/app-portal/pages/post/components/medias/view.html", + controller: function () { + var ctrl = this; + ctrl.activeMedia = function (media) { + var currentItem = null; + if (ctrl.post.mediaNavs === null) { + ctrl.post.mediaNavs = []; + } + $.each(ctrl.post.mediaNavs, function (i, e) { + if (e.mediaId === media.id) { + e.isActived = media.isActived; + currentItem = e; + return false; + } + }); + if (currentItem === null) { + currentItem = { + description: + media.description !== "undefined" ? media.description : "", + image: media.filePath, + mediaId: media.id, + post: ctrl.post.id, + specificulture: media.specificulture, + position: 0, + priority: ctrl.post.mediaNavs.length + 1, + isActived: true, + }; + media.isHidden = true; + ctrl.post.mediaNavs.push(currentItem); + } + }; + }, + bindings: { + post: "=", + medias: "=", + loadMedia: "&", + onDelete: "&", + onUpdate: "&", + }, +}); + +app.component("postMain", { + templateUrl: "/mix-app/views/app-portal/pages/post/components/main/view.html", + bindings: { + post: "=", + }, controller: [ "$rootScope", "$scope", - "ngAppSettings", function ($rootScope, $scope) { var ctrl = this; - ctrl.updatePageExport = function (value, isSelected) { - // Filter actived page - var idx = (ctrl.selectedExport.pages = angular.copy( - $rootScope.filterArray(ctrl.exportData.pages, ["isActived"], [true]) - )); - - // // Loop actived page - // angular.forEach(ctrl.selectedExport.pages, function (e) { - // // filter list actived modules - // e.moduleNavs = angular.copy($rootScope.filterArray(e.moduleNavs, ['isActived'], [true])); - - // // Loop actived modules - // angular.forEach(e.moduleNavs, function (n) { - // // filter list actived data - // n.module.data.items = angular.copy($rootScope.filterArray(n.module.data.items, ['isActived'], [true])); - // $rootScope.removeObjectByKey(ctrl.exportData.modules, 'id', n.moduleId); - // $rootScope.removeObjectByKey(ctrl.selectedExport.modules, 'id', n.moduleId); - // }); - // }); - }; - ctrl.isSelected = function (value) { - return ctrl.selectedValues.indexOf(value) >= 0; - }; - ctrl.selectAll = function (arr) { - ctrl.selectedList.data = []; - angular.forEach(arr, function (e) { - e.isActived = ctrl.selectedList.isSelectAll; - e.isExportData = ctrl.selectedList.isExportData; - }); - ctrl.updatePageExport(); + ctrl.translate = $rootScope.translate; + ctrl.generateSeo = function () { + if (ctrl.post) { + if (!ctrl.post.seoName) { + ctrl.post.seoName = $rootScope.generateKeyword( + ctrl.post.title, + "-" + ); + } + if (!ctrl.post.seoTitle) { + ctrl.post.seoTitle = ctrl.post.title; + } + if (!ctrl.post.seoDescription === null) { + ctrl.post.seoDescription = ctrl.post.excerpt; + } + if (!ctrl.post.seoKeywords) { + ctrl.post.seoKeywords = ctrl.post.title; + } + } }; }, ], +}); + +app.component("postParents", { + templateUrl: + "/mix-app/views/app-portal/pages/post/components/parents/view.html", bindings: { - exportData: "=", - selectedExport: "=", + post: "=", + onDelete: "&", + onUpdate: "&", }, }); -app.component("themeExportPosts", { +app.component("postModules", { templateUrl: - "/mix-app/views/app-portal/pages/theme/components/theme-export-posts/view.html", + "/mix-app/views/app-portal/pages/post/components/modules/view.html", controller: [ "$rootScope", "$scope", "ngAppSettings", - function ($rootScope, $scope) { + "SharedModuleDataService", + function ($rootScope, $scope, ngAppSettings, moduleDataService) { var ctrl = this; - ctrl.updatePostExport = function (value, isSelected) { - // Filter actived post - var idx = (ctrl.selectedExport.posts = angular.copy( - $rootScope.filterArray(ctrl.exportData.posts, ["isActived"], [true]) - )); + ctrl.request = angular.copy(ngAppSettings.request); + ctrl.translate = function (keyword, wrap, defaultValue) { + return $rootScope.translate(keyword, wrap, defaultValue); }; - ctrl.isSelected = function (value) { - return ctrl.selectedValues.indexOf(value) >= 0; + + ctrl.removeData = function (id, moduleId) { + $rootScope.showConfirm( + ctrl, + "removeDataConfirmed", + [id, moduleId], + null, + "Remove Data", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); }; - ctrl.selectAll = function (arr) { - ctrl.selectedList.data = []; - angular.forEach(arr, function (e) { - e.isActived = ctrl.selectedList.isSelectAll; - e.isExportData = ctrl.selectedList.isExportData; - }); - ctrl.updatePostExport(); + ctrl.removeDataConfirmed = async function (id, moduleId) { + $rootScope.isBusy = true; + var result = await moduleDataService.removeModuleData(id); + if (result.isSucceed) { + ctrl.loadModuleDatas(moduleId); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + ctrl.saveDataCallback = function (data) { + if (data) { + ctrl.loadModuleDatas(data.moduleId); + } + }; + ctrl.loadModuleDatas = async function (id, pageIndex) { + $rootScope.isBusy = true; + $scope.dataColumns = []; + var request = angular.copy(ngAppSettings.request); + request.query = "?module_id=" + id + "&post_id=" + ctrl.post.id; + if (pageIndex) { + request.pageIndex = pageIndex; + } + var response = await moduleDataService.getModuleDatas(request); + if (response.isSucceed) { + var nav = $rootScope.findObjectByKey( + ctrl.post.moduleNavs, + "moduleId", + id + ); + if (nav) { + nav.module.data = response.data; + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + + ctrl.updateDataInfos = async function (items) { + $rootScope.isBusy = true; + var resp = await moduleDataService.updateInfos(items); + if (resp && resp.isSucceed) { + $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(); + } }; }, ], bindings: { - exportData: "=", - selectedExport: "=", + post: "=", + onDelete: "&", + onUpdate: "&", }, }); -var demo = { - initDashboardPageCharts: function (incomes, services) { - incomes = incomes || [ - 50, - 150, - 100, - 190, - 130, - 90, - 150, - 160, - 120, - 140, - 190, - 95, - ]; - chartColor = "#eeeeee"; - // General configuration for the charts with Line gradientStroke - gradientChartOptionsConfiguration = { - maintainAspectRatio: false, - legend: { - display: false, - }, - tooltips: { - bodySpacing: 4, - mode: "nearest", - intersect: 0, - position: "nearest", - xPadding: 10, - yPadding: 10, - caretPadding: 10, - }, - responsive: 1, - scales: { - yAxes: [ - { - display: 0, - - ticks: { - display: false, - }, - gridLines: { - zeroLineColor: "transparent", - drawTicks: false, - display: false, - drawBorder: false, - }, - }, - ], - xAxes: [ - { - display: 0, - - ticks: { - display: false, - }, - gridLines: { - zeroLineColor: "transparent", - drawTicks: false, - display: false, - drawBorder: false, - }, - }, - ], - }, - layout: { - padding: { left: 0, right: 0, top: 15, bottom: 15 }, - }, - }; - - gradientChartOptionsConfigurationWithNumbersAndGrid = { - maintainAspectRatio: false, - legend: { - display: false, - }, - tooltips: { - bodySpacing: 4, - mode: "nearest", - intersect: 0, - position: "nearest", - xPadding: 10, - yPadding: 10, - caretPadding: 10, - }, - responsive: true, - scales: { - yAxes: [ - { - gridLines: { - zeroLineColor: "transparent", - drawBorder: false, - }, - }, - ], - xAxes: [ - { - display: 0, - - ticks: { - display: false, - }, - gridLines: { - zeroLineColor: "transparent", - drawTicks: false, - display: false, - drawBorder: false, - }, - }, - ], - }, - layout: { - padding: { left: 0, right: 0, top: 15, bottom: 15 }, - }, - }; - - var ctx = document.getElementById("bigDashboardChart").getContext("2d"); - - var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0); - gradientStroke.addColorStop(0, "#80b6f4"); - gradientStroke.addColorStop(1, chartColor); - - var gradientFill = ctx.createLinearGradient(0, 200, 0, 50); - gradientFill.addColorStop(0, "rgba(128, 182, 244, 0)"); - gradientFill.addColorStop(1, "rgba(255, 255, 255, 0.24)"); - - var myChart = new Chart(ctx, { - type: "bar", - data: { - labels: [ - "JAN", - "FEB", - "MAR", - "APR", - "MAY", - "JUN", - "JUL", - "AUG", - "SEP", - "OCT", - "NOV", - "DEC", - ], - datasets: [ - { - type: "line", - label: "Incomes", - borderColor: chartColor, - pointBorderColor: chartColor, - pointBackgroundColor: "red", - pointHoverBackgroundColor: "#1e3d60", - pointHoverBorderColor: chartColor, - pointBorderWidth: 1, - pointHoverRadius: 7, - pointHoverBorderWidth: 2, - pointRadius: 5, - fill: true, - backgroundColor: gradientFill, - borderWidth: 2, - data: incomes, - }, - { - label: "Services", - //borderColor: chartColor, - //pointBorderColor: chartColor, - //pointBackgroundColor: "#1e3d60", - //pointHoverBackgroundColor: "#1e3d60", - //pointHoverBorderColor: chartColor, - //pointBorderWidth: 1, - //pointHoverRadius: 7, - //pointHoverBorderWidth: 2, - //pointRadius: 5, - //fill: true, - backgroundColor: "yellow", - //borderWidth: 2, - data: services, - }, - ], - }, - options: { - layout: { - padding: { - left: 20, - right: 20, - top: 0, - bottom: 0, - }, - }, - maintainAspectRatio: false, - tooltips: { - backgroundColor: "#fff", - titleFontColor: "#333", - bodyFontColor: "#666", - bodySpacing: 4, - xPadding: 12, - mode: "nearest", - intersect: 0, - position: "nearest", - }, - legend: { - position: "bottom", - fillStyle: "#FFF", - display: false, - }, - scales: { - yAxes: [ - { - ticks: { - fontColor: "rgba(255,255,255,0.4)", - fontStyle: "bold", - beginAtZero: true, - maxTicksLimit: 5, - padding: 10, - }, - gridLines: { - drawTicks: true, - drawBorder: false, - display: true, - color: "rgba(255,255,255,0.1)", - zeroLineColor: "transparent", - }, - }, - ], - xAxes: [ - { - gridLines: { - zeroLineColor: "transparent", - display: false, - }, - ticks: { - padding: 10, - fontColor: "rgba(255,255,255,0.4)", - fontStyle: "bold", - }, - }, - ], - }, - }, - }); +app.component("postAdvanced", { + templateUrl: + "/mix-app/views/app-portal/pages/post/components/post-advanced/view.html", + bindings: { + model: "=", + additionalData: "=", }, -}; + controller: [ + "$rootScope", + "$scope", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.translate = $rootScope.translate; + ctrl.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; + }; + }, + ], +}); -modules.component("actions", { - templateUrl: "/mix-app/views/app-portal/components/actions/actions.html", +app.component("postContent", { + templateUrl: + "/mix-app/views/app-portal/pages/post/components/post-content/view.html", bindings: { - primaryUrl: "=", - primaryTitle: "=", - primaryIcon: "=", - previewUrl: "=", - backUrl: "=", - contentUrl: "=", - onClearCache: "&?", - onSubmit: "&?", + model: "=", + additionalData: "=", }, controller: [ "$rootScope", "$scope", - "$location", - function ($rootScope, $scope, $location) { + "ngAppSettings", + "PostRestService", + function ($rootScope, $scope, ngAppSettings, service) { var ctrl = this; - ctrl.visible = $rootScope.visible; - ctrl.back = function () { - // ctrl.backUrl = ctrl.backUrl || "/admin"; - // $location.url(ctrl.backUrl); - if (ctrl.backUrl) { - $location.url(ctrl.backUrl); + ctrl.request = angular.copy(ngAppSettings.request); + ctrl.translate = $rootScope.translate; + ctrl.relatedData = {}; + ctrl.$onInit = function () { + ctrl.backUrl = `/portal/post/details`; + }; + ctrl.generateSeo = function () { + if (ctrl.model) { + if (ctrl.model.seoName === null || ctrl.model.seoName === "") { + ctrl.model.seoName = $rootScope.generateKeyword( + ctrl.model.title, + "-" + ); + } + if (ctrl.model.seoTitle === null || ctrl.model.seoTitle === "") { + ctrl.model.seoTitle = ctrl.model.title; + } + if ( + ctrl.model.seoDescription === null || + ctrl.model.seoDescription === "" + ) { + ctrl.model.seoDescription = ctrl.model.excerpt; + } + if ( + ctrl.model.seoKeywords === null || + ctrl.model.seoKeywords === "" + ) { + ctrl.model.seoKeywords = ctrl.model.title; + } + } + }; + ctrl.getListRelated = async function (pageIndex) { + if (pageIndex !== undefined) { + ctrl.request.pageIndex = pageIndex; + } + if (ctrl.request.fromDate !== null) { + var d = new Date(ctrl.request.fromDate); + ctrl.request.fromDate = d.toISOString(); + } + if (ctrl.request.toDate !== null) { + var d = new Date(ctrl.request.toDate); + ctrl.request.toDate = d.toISOString(); + } + var resp = await service.getList(ctrl.request); + if (resp && resp.isSucceed) { + ctrl.relatedData = angular.copy(resp.data); + ctrl.relatedData.items = []; + angular.forEach(resp.data.items, (element) => { + var existed = $rootScope.findObjectByKey( + ctrl.model.postNavs, + ["sourceId", "destinationId"], + [ctrl.model.id, element.id] + ); + + var obj = { + description: element.title, + destinationId: element.id, + image: element.image, + isActived: existed !== null, + sourceId: ctrl.model.id, + specificulture: ctrl.model.specificulture, + status: "Published", + }; + + ctrl.relatedData.items.push(obj); + }); + console.log(ctrl.relatedData); + $rootScope.isBusy = false; + $scope.$apply(); } else { - window.history.back(); + $rootScope.showErrors(getData.errors); + $rootScope.isBusy = false; + $scope.$apply(); } }; - ctrl.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; + }, + ], +}); + +modules.component("relatedNavs", { + templateUrl: + "/mix-app/views/app-portal/pages/post/components/related-navigations/view.html", + bindings: { + request: "=", + prefix: "=", + sourceId: "=", + culture: "=", + navs: "=", + data: "=", + categories: "=", + postTypes: "=", + loadData: "&", + }, + controller: [ + "$rootScope", + "$scope", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.selected = null; + ctrl.activeItem = function (item, index) { + var currentItem = $rootScope.findObjectByKey( + ctrl.navs, + ["sourceId", "destinationId"], + [ctrl.sourceId, item.id] + ); + if (currentItem === null) { + currentItem = item; + currentItem.priority = ctrl.navs.length + 1; + ctrl.navs.push(currentItem); + ctrl.data.items.splice(index, 1); + } }; - ctrl.submit = function ($event) { - if (ctrl.onSubmit) { - $event.preventDefault(); - ctrl.onSubmit(); - return; + ctrl.updateOrders = function (index) { + ctrl.navs.splice(index, 1); + for (var i = 0; i < ctrl.data.length; i++) { + ctrl.navs[i].priority = i + 1; + } + }; + ctrl.load = async function (pageIndex) { + if (pageIndex !== undefined) { + ctrl.request.pageIndex = pageIndex; + } + ctrl.data = await ctrl.loadData({ pageIndex: ctrl.request.pageIndex }); + $scope.$apply(); + }; + ctrl.checkActived = function (item) { + if (ctrl.navs) { + return ctrl.navs.find(function (nav) { + return nav.destinationId === item.id; + }); + } + }; + }, + ], +}); + +app.component("postSeo", { + templateUrl: "/mix-app/views/app-portal/pages/post/components/seo/view.html", + bindings: { + post: "=", + onDelete: "&", + onUpdate: "&", + }, +}); + +app.component("serviceMain", { + templateUrl: + "/mix-app/views/app-portal/pages/service/components/main/view.html", + controller: [ + "$rootScope", + function ($rootScope) { + var ctrl = this; + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.gennerateName = function () { + if ( + !ctrl.model.id || + ctrl.model.name === null || + ctrl.model.name === "" + ) { + ctrl.model.name = $rootScope.generateKeyword(ctrl.model.title, "_"); } }; - ctrl.clearCache = function () { - ctrl.onClearCache(); + }, + ], + bindings: { + model: "=", + }, +}); + +app.component("themeExportModules", { + templateUrl: + "/mix-app/views/app-portal/pages/theme/components/theme-export-modules/view.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.updateModuleExport = function () { + ctrl.selectedExport.modules = angular.copy( + $rootScope.filterArray(ctrl.exportData.modules, ["isActived"], [true]) + ); + // angular.forEach(ctrl.selectedExport.modules,function(e){ + // e.data.items = angular.copy($rootScope.filterArray(e.data.items, ['isActived'], [true])); + // }); + }; + ctrl.selectAll = function (arr) { + ctrl.selectedList.data = []; + angular.forEach(arr, function (e) { + e.isActived = ctrl.selectedList.isSelectAll; + e.isExportData = ctrl.selectedList.isExportData; + }); + ctrl.updateModuleExport(); + }; + }, + ], + bindings: { + exportData: "=", + selectedExport: "=", + }, +}); + +app.component("themeExportMixDatabases", { + templateUrl: + "/mix-app/views/app-portal/pages/theme/components/theme-export-mix-databases/view.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.updateMixDatabaseExport = function () { + ctrl.selectedExport.mixDatabases = angular.copy( + $rootScope.filterArray( + ctrl.exportData.mixDatabases, + ["isActived"], + [true] + ) + ); + // angular.forEach(ctrl.selectedExport.mixDatabases,function(e){ + // e.data = angular.copy($rootScope.filterArray(e.data, ['isActived'], [true])); + // }); + }; + ctrl.selectAll = function (arr) { + ctrl.selectedList.data = []; + angular.forEach(arr, function (e) { + e.isActived = ctrl.selectedList.isSelectAll; + e.isExportData = ctrl.selectedList.isExportData; + }); + ctrl.updateMixDatabaseExport(); }; }, ], + bindings: { + exportData: "=", + selectedExport: "=", + }, }); -modules.component("aceEditor", { +app.component("themeExportPages", { templateUrl: - "/mix-app/views/app-portal/components/ace-editor/ace-editor.html", + "/mix-app/views/app-portal/pages/theme/components/theme-export-pages/view.html", controller: [ "$rootScope", "$scope", "ngAppSettings", - function ($rootScope, $scope, ngAppSettings) { + function ($rootScope, $scope) { var ctrl = this; - ctrl.previousId = null; - ctrl.editor = null; - ctrl.id = Math.floor(Math.random() * 100) + 1; - ctrl.$onChanges = (changes) => { - if (changes.content) { - ctrl.updateEditors(); - } - }; + ctrl.updatePageExport = function (value, isSelected) { + // Filter actived page + var idx = (ctrl.selectedExport.pages = angular.copy( + $rootScope.filterArray(ctrl.exportData.pages, ["isActived"], [true]) + )); - this.$doCheck = function () { - if (ctrl.previousId != null && ctrl.previousId !== ctrl.contentId) { - ctrl.previousId = ctrl.contentId; - ctrl.updateEditors(); - } - }.bind(this); - ctrl.initAce = function () { - setTimeout(() => { - ctrl.previousId = ctrl.contentId; - ctrl.updateEditors(); - $scope.$apply(); - }, 200); + // // Loop actived page + // angular.forEach(ctrl.selectedExport.pages, function (e) { + // // filter list actived modules + // e.moduleNavs = angular.copy($rootScope.filterArray(e.moduleNavs, ['isActived'], [true])); + + // // Loop actived modules + // angular.forEach(e.moduleNavs, function (n) { + // // filter list actived data + // n.module.data.items = angular.copy($rootScope.filterArray(n.module.data.items, ['isActived'], [true])); + // $rootScope.removeObjectByKey(ctrl.exportData.modules, 'id', n.moduleId); + // $rootScope.removeObjectByKey(ctrl.selectedExport.modules, 'id', n.moduleId); + // }); + // }); }; - ctrl.updateContent = function (content) { - ctrl.editor.setValue(content); + ctrl.isSelected = function (value) { + return ctrl.selectedValues.indexOf(value) >= 0; }; - ctrl.updateEditors = function () { - $.each($("#code-editor-" + ctrl.id), function (i, e) { - //var container = $(this); - ace.require("ace/ext/language_tools"); - if (e) { - var editor = ace.edit(e); - switch (ctrl.ext) { - case ".json": - editor.session.setMode("ace/mode/json"); - break; - case ".js": - editor.session.setMode("ace/mode/javascript"); - break; - case ".css": - editor.session.setMode("ace/mode/css"); - break; - case ".cshtml": - editor.session.setMode("ace/mode/razor"); - break; - case ".cs": - editor.session.setMode("ace/mode/csharp"); - break; - default: - editor.session.setMode("ace/mode/razor"); - break; - } - editor.setTheme("ace/theme/chrome"); - //editor.setReadOnly(true); - if (ctrl.content) { - editor.setValue(ctrl.content); - } - editor.$blockScrolling = Infinity; - editor.session.setUseWrapMode(true); - editor.setOptions({ - enableBasicAutocompletion: true, - enableSnippets: true, - enableLiveAutocompletion: false, - maxLines: 50, - fontSize: 11, - }); - editor.getSession().on("change", function (e) { - // e.type, etc - ctrl.content = editor.getValue(); - }); - editor.getSession().on("paste", function (e) { - // e.type, etc - ctrl.content = editor.getValue(); - }); - editor.commands.addCommand({ - name: "saveFile", - bindKey: { - win: "Ctrl-S", - mac: "Command-S", - sender: "editor|cli", - }, - exec: function (env, args, request) { - var btn = document.getElementById("btnToSubmit"); - btn.click(); - }, - }); - ctrl.editor = editor; - } + ctrl.selectAll = function (arr) { + ctrl.selectedList.data = []; + angular.forEach(arr, function (e) { + e.isActived = ctrl.selectedList.isSelectAll; + e.isExportData = ctrl.selectedList.isExportData; }); + ctrl.updatePageExport(); }; }, ], bindings: { - content: "=", - contentId: "=", - ext: "=", + exportData: "=", + selectedExport: "=", }, }); -modules.component("additionalColumn", { +app.component("themeExportPosts", { templateUrl: - "/mix-app/views/app-portal/components/additional-column/view.html", - bindings: { - model: "=", - additionalData: "=", - }, + "/mix-app/views/app-portal/pages/theme/components/theme-export-posts/view.html", controller: [ "$rootScope", "$scope", - "RestMixDatabaseColumnPortalService", - "RestMixDatabaseDataPortalService", - function ($rootScope, $scope, columnService, dataService) { + "ngAppSettings", + function ($rootScope, $scope) { var ctrl = this; - ctrl.value = {}; - ctrl.column = { - dataType: "Text", - mixDatabaseName: "sys_additional_column", - mixDatabaseId: 6, - status: "Published", - }; - ctrl.selectedCol = null; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.$onInit = async function () {}; - ctrl.addAttr = async function () { - if (ctrl.column.name) { - var current = $rootScope.findObjectByKey( - ctrl.additionalData.columns, - "name", - ctrl.column.name - ); - if (current) { - $rootScope.showErrors(["Field " + ctrl.column.name + " existed!"]); - } else { - ctrl.column.priority = ctrl.additionalData.columns.length + 1; - $rootScope.isBusy = true; - var saveField = await columnService.create(ctrl.column); - $rootScope.isBusy = false; - if (saveField.isSucceed) { - ctrl.additionalData.columns.push(saveField.data); - if (ctrl.additionalData.parentId) { - await dataService.save(ctrl.additionalData); - } - //reset column option - ctrl.column.title = ""; - ctrl.column.name = ""; - ctrl.column.dataType = "Text"; - } else { - $rootScope.showErrors(saveField.errors); - } - $scope.$apply(); - } - } else { - $rootScope.showErrors(["Please add column Name"]); - } - }; - - ctrl.generateName = function (col) { - col.name = $rootScope.generateKeyword(col.title, "_", true, true); - }; - ctrl.showReferences = function (col) { - ctrl.colRef = col; - $("#modal-navs").modal("show"); + ctrl.updatePostExport = function (value, isSelected) { + // Filter actived post + var idx = (ctrl.selectedExport.posts = angular.copy( + $rootScope.filterArray(ctrl.exportData.posts, ["isActived"], [true]) + )); }; - ctrl.referenceCallback = async function (selected) { - if (selected && selected.length) { - ctrl.colRef.reference = selected; - ctrl.colRef.referenceId = selected[0].id; - await columnService.save(ctrl.colRef); - } - $("#modal-navs").modal("hide"); + ctrl.isSelected = function (value) { + return ctrl.selectedValues.indexOf(value) >= 0; }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.additionalData.columns.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.additionalData.columns.splice(ctrl.dragStartIndex + 1, 1); - } - angular.forEach(ctrl.additionalData.columns, function (e, i) { - e.priority = i; + ctrl.selectAll = function (arr) { + ctrl.selectedList.data = []; + angular.forEach(arr, function (e) { + e.isActived = ctrl.selectedList.isSelectAll; + e.isExportData = ctrl.selectedList.isExportData; }); - }; - - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - }; - - ctrl.removeAttribute = function (val, index) { - $rootScope.showConfirm( - ctrl, - "removeAttributeConfirmed", - [val, index], - null, - "Remove Field", - "Deleted data will not able to recover, are you sure you want to delete this item?" - ); - }; - ctrl.removeAttributeConfirmed = async function (val, index) { - if (val.id) { - $rootScope.isBusy = true; - var result = await columnService.delete([val.id]); - if (result.isSucceed) { - ctrl.additionalData.columns.splice(index, 1); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(result.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - } else { - ctrl.additionalData.columns.splice(index, 1); - } + ctrl.updatePostExport(); }; }, ], + bindings: { + exportData: "=", + selectedExport: "=", + }, }); -modules.component("confirm", { - templateUrl: "/mix-app/views/app-portal/components/confirm/confirm.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - function ($rootScope, $scope) { - var ctrl = this; - ctrl.executeFunctionByName = async function ( - functionName, - args, - context - ) { - var result = await $rootScope.executeFunctionByName( - functionName, - args, - context - ); - if (result) { - $scope.$apply(); - } - }; - }, - ], - bindings: { - message: "=", +var demo = { + initDashboardPageCharts: function (incomes, services) { + incomes = incomes || [ + 50, + 150, + 100, + 190, + 130, + 90, + 150, + 160, + 120, + 140, + 190, + 95, + ]; + chartColor = "#eeeeee"; + // General configuration for the charts with Line gradientStroke + gradientChartOptionsConfiguration = { + maintainAspectRatio: false, + legend: { + display: false, + }, + tooltips: { + bodySpacing: 4, + mode: "nearest", + intersect: 0, + position: "nearest", + xPadding: 10, + yPadding: 10, + caretPadding: 10, + }, + responsive: 1, + scales: { + yAxes: [ + { + display: 0, + + ticks: { + display: false, + }, + gridLines: { + zeroLineColor: "transparent", + drawTicks: false, + display: false, + drawBorder: false, + }, + }, + ], + xAxes: [ + { + display: 0, + + ticks: { + display: false, + }, + gridLines: { + zeroLineColor: "transparent", + drawTicks: false, + display: false, + drawBorder: false, + }, + }, + ], + }, + layout: { + padding: { left: 0, right: 0, top: 15, bottom: 15 }, + }, + }; + + gradientChartOptionsConfigurationWithNumbersAndGrid = { + maintainAspectRatio: false, + legend: { + display: false, + }, + tooltips: { + bodySpacing: 4, + mode: "nearest", + intersect: 0, + position: "nearest", + xPadding: 10, + yPadding: 10, + caretPadding: 10, + }, + responsive: true, + scales: { + yAxes: [ + { + gridLines: { + zeroLineColor: "transparent", + drawBorder: false, + }, + }, + ], + xAxes: [ + { + display: 0, + + ticks: { + display: false, + }, + gridLines: { + zeroLineColor: "transparent", + drawTicks: false, + display: false, + drawBorder: false, + }, + }, + ], + }, + layout: { + padding: { left: 0, right: 0, top: 15, bottom: 15 }, + }, + }; + + var ctx = document.getElementById("bigDashboardChart").getContext("2d"); + + var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0); + gradientStroke.addColorStop(0, "#80b6f4"); + gradientStroke.addColorStop(1, chartColor); + + var gradientFill = ctx.createLinearGradient(0, 200, 0, 50); + gradientFill.addColorStop(0, "rgba(128, 182, 244, 0)"); + gradientFill.addColorStop(1, "rgba(255, 255, 255, 0.24)"); + + var myChart = new Chart(ctx, { + type: "bar", + data: { + labels: [ + "JAN", + "FEB", + "MAR", + "APR", + "MAY", + "JUN", + "JUL", + "AUG", + "SEP", + "OCT", + "NOV", + "DEC", + ], + datasets: [ + { + type: "line", + label: "Incomes", + borderColor: chartColor, + pointBorderColor: chartColor, + pointBackgroundColor: "red", + pointHoverBackgroundColor: "#1e3d60", + pointHoverBorderColor: chartColor, + pointBorderWidth: 1, + pointHoverRadius: 7, + pointHoverBorderWidth: 2, + pointRadius: 5, + fill: true, + backgroundColor: gradientFill, + borderWidth: 2, + data: incomes, + }, + { + label: "Services", + //borderColor: chartColor, + //pointBorderColor: chartColor, + //pointBackgroundColor: "#1e3d60", + //pointHoverBackgroundColor: "#1e3d60", + //pointHoverBorderColor: chartColor, + //pointBorderWidth: 1, + //pointHoverRadius: 7, + //pointHoverBorderWidth: 2, + //pointRadius: 5, + //fill: true, + backgroundColor: "yellow", + //borderWidth: 2, + data: services, + }, + ], + }, + options: { + layout: { + padding: { + left: 20, + right: 20, + top: 0, + bottom: 0, + }, + }, + maintainAspectRatio: false, + tooltips: { + backgroundColor: "#fff", + titleFontColor: "#333", + bodyFontColor: "#666", + bodySpacing: 4, + xPadding: 12, + mode: "nearest", + intersect: 0, + position: "nearest", + }, + legend: { + position: "bottom", + fillStyle: "#FFF", + display: false, + }, + scales: { + yAxes: [ + { + ticks: { + fontColor: "rgba(255,255,255,0.4)", + fontStyle: "bold", + beginAtZero: true, + maxTicksLimit: 5, + padding: 10, + }, + gridLines: { + drawTicks: true, + drawBorder: false, + display: true, + color: "rgba(255,255,255,0.1)", + zeroLineColor: "transparent", + }, + }, + ], + xAxes: [ + { + gridLines: { + zeroLineColor: "transparent", + display: false, + }, + ticks: { + padding: 10, + fontColor: "rgba(255,255,255,0.4)", + fontStyle: "bold", + }, + }, + ], + }, + }, + }); }, -}); +}; -modules.component("customImage", { +modules.component("aceEditor", { templateUrl: - "/mix-app/views/app-portal/components/custom-image/custom-image.html", - bindings: { - header: "=?", - description: "=?", - src: "=", - srcUrl: "=", - w: "=?", - h: "=?", - rto: "=?", - postedFile: "=?", - type: "=?", - folder: "=?", - auto: "=", - onDelete: "&?", - onUpdate: "&?", - }, + "/mix-app/views/app-portal/components/ace-editor/ace-editor.html", controller: [ "$rootScope", "$scope", - "$uibModal", "ngAppSettings", - "MediaService", - function ($rootScope, $scope, $uibModal, ngAppSettings, mediaService) { + function ($rootScope, $scope, ngAppSettings) { var ctrl = this; - ctrl.isAdmin = $rootScope.isAdmin; - var image_placeholder = "/mix-app/assets/img/image_placeholder.jpg"; - ctrl.isImage = false; - ctrl.croppedStream = null; - ctrl.mediaNavs = []; - ctrl.options = {}; - ctrl.$onInit = function () { - ctrl.srcUrl = ctrl.srcUrl || image_placeholder; - ctrl.isImage = ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg|ico)/g); - ctrl.id = Math.floor(Math.random() * 100); - }; - ctrl.calImageSize = function () { - if (ctrl.w) { - ctrl.h = ctrl.h || ctrl.w / ctrl.rto; - ctrl.rto = ctrl.rto || ctrl.w / ctrl.h; - } - if (ctrl.h) { - ctrl.w = ctrl.w || ctrl.h * ctrl.rto; - ctrl.rto = ctrl.rto || ctrl.w / ctrl.h; + ctrl.previousId = null; + ctrl.editor = null; + ctrl.id = Math.floor(Math.random() * 100) + 1; + ctrl.$onChanges = (changes) => { + if (changes.content) { + ctrl.updateEditors(); } - - ctrl.maxHeight = ctrl.maxHeight || "200px"; - ctrl.options = { - boundary: { width: 150 * ctrl.rto, height: 150 }, - render: { width: 1000 * ctrl.rto, height: 1000 }, - output: { width: ctrl.w, height: ctrl.h }, - }; - }; - - ctrl.mediaFile = { - file: null, - fullPath: "", - folder: ctrl.folder, - title: ctrl.title, - description: ctrl.description, }; - ctrl.croppieCallback = function (result) { - if (result) { - ctrl.srcUrl = result.filePath; - } else if (ctrl.file) { - ctrl.uploadFile(ctrl.file); + this.$doCheck = function () { + if (ctrl.previousId != null && ctrl.previousId !== ctrl.contentId) { + ctrl.previousId = ctrl.contentId; + ctrl.updateEditors(); } + }.bind(this); + ctrl.initAce = function () { + setTimeout(() => { + ctrl.previousId = ctrl.contentId; + ctrl.updateEditors(); + $scope.$apply(); + }, 200); }; - - ctrl.media = {}; - ctrl.$doCheck = function () { - if (ctrl.src !== ctrl.srcUrl && ctrl.srcUrl != image_placeholder) { - ctrl.src = ctrl.srcUrl; - ctrl.isImage = ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); - } - }.bind(ctrl); - - ctrl.selectFile = function (files) { - if (files !== undefined && files !== null && files.length > 0) { - ctrl.file = files[0]; - ctrl.mediaFile.fileFolder = ctrl.folder || "Media"; - ctrl.mediaFile.title = ctrl.title || ""; - ctrl.mediaFile.description = ctrl.description || ""; - ctrl.mediaFile.file = ctrl.file; - mediaService.openCroppie(ctrl.file, ctrl, true); - } + ctrl.updateContent = function (content) { + ctrl.editor.setValue(content); }; - - ctrl.uploadFile = async function (file) { - if (file !== null) { - $rootScope.isBusy = true; - var getMedia = await mediaService.getSingle(["portal"]); - if (getMedia.isSucceed) { - ctrl.mediaFile.fileName = file.name.substring( - 0, - file.name.lastIndexOf(".") - ); - ctrl.mediaFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - var media = getMedia.data; - media.fileFolder = ctrl.folder || "Media"; - media.extension = ctrl.mediaFile.extension; - media.title = ctrl.title || ""; - media.description = ctrl.description || ""; - media.mediaFile = ctrl.mediaFile; - var resp = await mediaService.save( - media, - null, - ctrl.onUploadFileProgress - ); - if (resp && resp.isSucceed) { - ctrl.src = resp.data.filePath; - ctrl.srcUrl = resp.data.filePath; - ctrl.isImage = ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $rootScope.isBusy = false; - $scope.$apply(); + ctrl.updateEditors = function () { + $.each($("#code-editor-" + ctrl.id), function (i, e) { + //var container = $(this); + ace.require("ace/ext/language_tools"); + if (e) { + var editor = ace.edit(e); + switch (ctrl.ext) { + case ".json": + editor.session.setMode("ace/mode/json"); + break; + case ".js": + editor.session.setMode("ace/mode/javascript"); + break; + case ".css": + editor.session.setMode("ace/mode/css"); + break; + case ".cshtml": + editor.session.setMode("ace/mode/razor"); + break; + case ".cs": + editor.session.setMode("ace/mode/csharp"); + break; + default: + editor.session.setMode("ace/mode/razor"); + break; } - } - } else { - return null; - } - }; - - ctrl.getBase64 = function (file) { - if (file !== null) { - $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); - if (ctrl.postedFile) { - ctrl.postedFile.fileName = file.name.substring( - 0, - file.name.lastIndexOf(".") - ); - ctrl.postedFile.extension = file.name.substring( - file.name.lastIndexOf(".") - ); - ctrl.postedFile.fileStream = reader.result; + editor.setTheme("ace/theme/chrome"); + //editor.setReadOnly(true); + if (ctrl.content) { + editor.setValue(ctrl.content); } - 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; + editor.$blockScrolling = Infinity; + editor.session.setUseWrapMode(true); + editor.setOptions({ + enableBasicAutocompletion: true, + enableSnippets: true, + enableLiveAutocompletion: false, + maxLines: 50, + fontSize: 11, + }); + editor.getSession().on("change", function (e) { + // e.type, etc + ctrl.content = editor.getValue(); + }); + editor.getSession().on("paste", function (e) { + // e.type, etc + ctrl.content = editor.getValue(); + }); + editor.commands.addCommand({ + name: "saveFile", + bindKey: { + win: "Ctrl-S", + mac: "Command-S", + sender: "editor|cli", + }, + exec: function (env, args, request) { + var btn = document.getElementById("btnToSubmit"); + btn.click(); + }, + }); + ctrl.editor = editor; + } + }); }; }, ], + bindings: { + content: "=", + contentId: "=", + ext: "=", + }, }); -modules.component("filterList", { - templateUrl: - "/mix-app/views/app-portal/components/filter-list/filter-list.html", +modules.component("actions", { + templateUrl: "/mix-app/views/app-portal/components/actions/actions.html", + bindings: { + primaryUrl: "=", + primaryTitle: "=", + primaryIcon: "=", + previewUrl: "=", + backUrl: "=", + contentUrl: "=", + onClearCache: "&?", + onSubmit: "&?", + }, controller: [ - "$scope", "$rootScope", - "ngAppSettings", - function ($scope, $rootScope, ngAppSettings) { + "$scope", + "$location", + function ($rootScope, $scope, $location) { var ctrl = this; - ctrl.dateRange = { - fromDate: null, - toDate: null, - }; - ctrl.init = function () { - if (!ctrl.orders) { - ctrl.orders = ngAppSettings.orders; - } - ctrl.directions = ngAppSettings.directions; - ctrl.pageSizes = ngAppSettings.pageSizes; - ctrl.statuses = []; - var statuses = ngAppSettings.contentStatuses; - if (ctrl.request && ctrl.request.contentStatuses) { - statuses = ctrl.request.contentStatuses; + ctrl.visible = $rootScope.visible; + ctrl.back = function () { + // ctrl.backUrl = ctrl.backUrl || "/admin"; + // $location.url(ctrl.backUrl); + if (ctrl.backUrl) { + $location.url(ctrl.backUrl); + } else { + window.history.back(); } - angular.forEach(statuses, function (val, i) { - ctrl.statuses.push({ - value: val, - title: val, - }); - }); }; - ctrl.apply = function (pageIndex) { - $rootScope.setRequest(ctrl.request, ctrl.key); - ctrl.callback({ pageIndex: pageIndex }); + ctrl.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; }; - ctrl.updateDate = function () { - ctrl.request.pageIndex = 0; - if (Date.parse(ctrl.dateRange.fromDate)) { - ctrl.request.fromDate = new Date( - 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; + ctrl.submit = function ($event) { + if (ctrl.onSubmit) { + $event.preventDefault(); + ctrl.onSubmit(); + return; } - $rootScope.setRequest(ctrl.request, ctrl.key); - ctrl.callback({ pageIndex: 0 }); + }; + ctrl.clearCache = function () { + ctrl.onClearCache(); }; }, ], - bindings: { - request: "=", - key: "=?", - orders: "=?", - createUrl: "=", - createText: "=", - callback: "&", - }, }); modules.component("additionalValue", { @@ -8788,378 +8399,441 @@ modules.component("additionalValue", { ], }); -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("githubReleases", { - templateUrl: "/mix-app/views/app-portal/components/github-releases/view.html", +modules.component("additionalColumn", { + templateUrl: + "/mix-app/views/app-portal/components/additional-column/view.html", + bindings: { + model: "=", + additionalData: "=", + }, controller: [ "$rootScope", - "$http", - function ($rootScope, $http) { + "$scope", + "RestMixDatabaseColumnPortalService", + "RestMixDatabaseDataPortalService", + function ($rootScope, $scope, columnService, dataService) { var ctrl = this; - ctrl.items = []; - ctrl.init = function () { - var req = { - method: "GET", - url: "https://api.github.com/repos/mixcore/mix.core/releases", - }; - ctrl.getGithubApiResult(req); + ctrl.value = {}; + ctrl.column = { + dataType: "Text", + mixDatabaseName: "sys_additional_column", + mixDatabaseId: 6, + status: "Published", }; - - ctrl.getGithubApiResult = async function (req) { - return $http(req).then( - function (resp) { - if (resp.status == "200") { - ctrl.items = resp.data; + ctrl.selectedCol = null; + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.$onInit = async function () {}; + ctrl.addAttr = async function () { + if (ctrl.column.name) { + var current = $rootScope.findObjectByKey( + ctrl.additionalData.columns, + "name", + ctrl.column.name + ); + if (current) { + $rootScope.showErrors(["Field " + ctrl.column.name + " existed!"]); + } else { + ctrl.column.priority = ctrl.additionalData.columns.length + 1; + $rootScope.isBusy = true; + var saveField = await columnService.create(ctrl.column); + $rootScope.isBusy = false; + if (saveField.isSucceed) { + ctrl.additionalData.columns.push(saveField.data); + if (ctrl.additionalData.parentId) { + await dataService.save(ctrl.additionalData); + } + //reset column option + ctrl.column.title = ""; + ctrl.column.name = ""; + ctrl.column.dataType = "Text"; } else { + $rootScope.showErrors(saveField.errors); } - }, - function (error) { - return { - isSucceed: false, - errors: [error.statusText || error.status], - }; + $scope.$apply(); + } + } else { + $rootScope.showErrors(["Please add column Name"]); + } + }; + + ctrl.generateName = function (col) { + col.name = $rootScope.generateKeyword(col.title, "_", true, true); + }; + ctrl.showReferences = function (col) { + ctrl.colRef = col; + $("#modal-navs").modal("show"); + }; + ctrl.referenceCallback = async function (selected) { + if (selected && selected.length) { + ctrl.colRef.reference = selected; + ctrl.colRef.referenceId = selected[0].id; + await columnService.save(ctrl.colRef); + } + $("#modal-navs").modal("hide"); + }; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.additionalData.columns.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.additionalData.columns.splice(ctrl.dragStartIndex + 1, 1); + } + angular.forEach(ctrl.additionalData.columns, function (e, i) { + e.priority = i; + }); + }; + + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; + }; + + ctrl.removeAttribute = function (val, index) { + $rootScope.showConfirm( + ctrl, + "removeAttributeConfirmed", + [val, index], + null, + "Remove Field", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + ctrl.removeAttributeConfirmed = async function (val, index) { + if (val.id) { + $rootScope.isBusy = true; + var result = await columnService.delete([val.id]); + if (result.isSucceed) { + ctrl.additionalData.columns.splice(index, 1); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(result.errors); + $rootScope.isBusy = false; + $scope.$apply(); } - ); + } else { + ctrl.additionalData.columns.splice(index, 1); + } }; }, ], - bindings: {}, }); -modules.component("googleAnalytic", { - templateUrl: "/mix-app/views/app-portal/components/google-analytic/view.html", - bindings: {}, +modules.component("confirm", { + templateUrl: "/mix-app/views/app-portal/components/confirm/confirm.html", controller: [ "$rootScope", - "ApiService", - "CommonService", - function ($rootScope, apiService, commonService) { + "$scope", + "ngAppSettings", + function ($rootScope, $scope) { var ctrl = this; - ctrl.init = function () { - if (gapi) { - gapi.analytics.ready(function () { - if ($rootScope.localizeSettings.data.Google_Client_Id) { - /** - * Authorize the user immediately if the user has already granted access. - * If no access has been created, render an authorize button inside the - * element with the ID "embed-api-auth-container". - */ - gapi.analytics.auth.authorize({ - container: "embed-api-auth-container", - //REPLACE WITH YOUR CLIENT ID - clientid: $rootScope.localizeSettings.data.Google_Client_Id, - }); - - /** - * Create a ViewSelector for the first view to be rendered inside of an - * element with the id "view-selector-1-container". - */ - var viewSelector1 = new gapi.analytics.ViewSelector({ - container: "view-selector-1-container", - }); - - /** - * Create a ViewSelector for the second view to be rendered inside of an - * element with the id "view-selector-2-container". - */ - var viewSelector2 = new gapi.analytics.ViewSelector({ - container: "view-selector-2-container", - }); - - /** - * Create a new ActiveUsers instance to be rendered inside of an - * element with the id "active-users-container" and poll for changes every - * five seconds. - */ - var activeUsers = new gapi.analytics.ext.ActiveUsers({ - container: "active-users-container", - pollingInterval: 5, - }); - /** - * Add CSS animation to visually show the when users come and go. - */ - activeUsers.once("success", function () { - var element = this.container.firstChild; - var timeout; - - this.on("change", function (data) { - var element = this.container.firstChild; - var animationClass = - data.delta > 0 ? "is-increasing" : "is-decreasing"; - element.className += " " + animationClass; - - clearTimeout(timeout); - timeout = setTimeout(function () { - element.className = element.className.replace( - / is-(increasing|decreasing)/g, - "" - ); - }, 3000); - }); - }); - - /** - * Create a ViewSelector for the second view to be rendered inside of an - * element with the id "view-selector-2-container". - */ - var viewSelector2 = new gapi.analytics.ViewSelector({ - container: "view-selector-2-container", - }); - - // Render both view selectors to the page. - // viewSelector1.execute(); - // viewSelector2.execute(); - - /** - * Create the first DataChart for top countries over the past 30 days. - * It will be rendered inside an element with the id "chart-1-container". - */ - var dataChart1 = new gapi.analytics.googleCharts.DataChart({ - query: { - // ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, - metrics: "ga:sessions", - dimensions: "ga:date", - "start-date": "30daysAgo", - "end-date": "yesterday", - }, - chart: { - container: "chart-1-container", - type: "LINE", - options: { - width: "95%", - legendTextStyle: { color: "#333" }, - titleTextStyle: { color: "#333" }, - backgroundColor: { fill: "transparent" }, - hAxis: { - textStyle: { color: "#333" }, - }, - vAxis: { - textStyle: { color: "#333" }, - }, - series: { - 0: { - color: - $rootScope.globalSettings.portalThemeSettings - .primaryColor, - }, - 1: { color: "#e7711b" }, - 2: { color: "#f1ca3a" }, - 3: { color: "#6f9654" }, - 4: { color: "#1c91c0" }, - 5: { color: "#43459d" }, - }, - }, - }, - }); + ctrl.executeFunctionByName = async function ( + functionName, + args, + context + ) { + var result = await $rootScope.executeFunctionByName( + functionName, + args, + context + ); + if (result) { + $scope.$apply(); + } + }; + }, + ], + bindings: { + message: "=", + }, +}); - /** - * Create the second DataChart for top countries over the past 30 days. - * It will be rendered inside an element with the id "chart-2-container". - */ - var dataChart2 = new gapi.analytics.googleCharts.DataChart({ - query: { - // ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, - metrics: "ga:sessions", - dimensions: "ga:country", - "start-date": "90daysAgo", - "end-date": "yesterday", - "max-results": 6, - sort: "-ga:sessions", - }, - chart: { - container: "chart-2-container", - type: "GEO", - options: { - width: "95%", - pieHole: 4 / 9, - }, - }, - }); +modules.component("customImage", { + templateUrl: + "/mix-app/views/app-portal/components/custom-image/custom-image.html", + bindings: { + header: "=?", + description: "=?", + src: "=", + srcUrl: "=", + w: "=?", + h: "=?", + rto: "=?", + postedFile: "=?", + type: "=?", + folder: "=?", + auto: "=", + onDelete: "&?", + onUpdate: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "$uibModal", + "ngAppSettings", + "MediaService", + function ($rootScope, $scope, $uibModal, ngAppSettings, mediaService) { + var ctrl = this; + ctrl.isAdmin = $rootScope.isAdmin; + var image_placeholder = "/mix-app/assets/img/image_placeholder.jpg"; + ctrl.isImage = false; + ctrl.croppedStream = null; + ctrl.mediaNavs = []; + ctrl.options = {}; + ctrl.$onInit = function () { + ctrl.srcUrl = ctrl.srcUrl || image_placeholder; + ctrl.isImage = ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg|ico)/g); + ctrl.id = Math.floor(Math.random() * 100); + }; + ctrl.calImageSize = function () { + if (ctrl.w) { + ctrl.h = ctrl.h || ctrl.w / ctrl.rto; + ctrl.rto = ctrl.rto || ctrl.w / ctrl.h; + } + if (ctrl.h) { + ctrl.w = ctrl.w || ctrl.h * ctrl.rto; + ctrl.rto = ctrl.rto || ctrl.w / ctrl.h; + } - dataChart1 - .set({ - query: { - ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, - }, - }) - .execute(); - dataChart2 - .set({ - query: { - ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, - }, - }) - .execute(); - activeUsers - .set({ - ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, - }) - .execute(); + ctrl.maxHeight = ctrl.maxHeight || "200px"; + ctrl.options = { + boundary: { width: 150 * ctrl.rto, height: 150 }, + render: { width: 1000 * ctrl.rto, height: 1000 }, + output: { width: ctrl.w, height: ctrl.h }, + }; + }; - // /** - // * Update the first dataChart when the first view selecter is changed. - // */ - // viewSelector1.on('change', function (ids) { - // dataChart1.set({ query: { ids: ids } }).execute(); - // // Start tracking active users for this view. - // activeUsers.set({ ids: ids }).execute(); - // }); + ctrl.mediaFile = { + file: null, + fullPath: "", + folder: ctrl.folder, + title: ctrl.title, + description: ctrl.description, + }; - // /** - // * Update the first dataChart when the first view selecter is changed. - // */ - // viewSelector2.on('change', function (ids) { - // dataChart2.set({ query: { ids: ids } }).execute(); - // // Start tracking active users for this view. - // activeUsers.set({ ids: ids }).execute(); - // }); + ctrl.croppieCallback = function (result) { + if (result) { + ctrl.srcUrl = result.filePath; + } else if (ctrl.file) { + ctrl.uploadFile(ctrl.file); + } + }; - // /** - // * Update the second dataChart when the second view selecter is changed. - // */ - // viewSelector2.on('change', function (ids) { - // dataChart2.set({ query: { ids: ids } }).execute(); - // }); + ctrl.media = {}; + ctrl.$doCheck = function () { + if (ctrl.src !== ctrl.srcUrl && ctrl.srcUrl != image_placeholder) { + ctrl.src = ctrl.srcUrl; + ctrl.isImage = ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); + } + }.bind(ctrl); + + ctrl.selectFile = function (files) { + if (files !== undefined && files !== null && files.length > 0) { + ctrl.file = files[0]; + ctrl.mediaFile.fileFolder = ctrl.folder || "Media"; + ctrl.mediaFile.title = ctrl.title || ""; + ctrl.mediaFile.description = ctrl.description || ""; + ctrl.mediaFile.file = ctrl.file; + mediaService.openCroppie(ctrl.file, ctrl, true); + } + }; + + ctrl.uploadFile = async function (file) { + if (file !== null) { + $rootScope.isBusy = true; + var getMedia = await mediaService.getSingle(["portal"]); + if (getMedia.isSucceed) { + ctrl.mediaFile.fileName = file.name.substring( + 0, + file.name.lastIndexOf(".") + ); + ctrl.mediaFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + var media = getMedia.data; + media.fileFolder = ctrl.folder || "Media"; + media.extension = ctrl.mediaFile.extension; + media.title = ctrl.title || ""; + media.description = ctrl.description || ""; + media.mediaFile = ctrl.mediaFile; + var resp = await mediaService.save( + media, + null, + ctrl.onUploadFileProgress + ); + if (resp && resp.isSucceed) { + ctrl.src = resp.data.filePath; + ctrl.srcUrl = resp.data.filePath; + ctrl.isImage = ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors(resp.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 () { + var index = reader.result.indexOf(",") + 1; + var base64 = reader.result.substring(index); + if (ctrl.postedFile) { + ctrl.postedFile.fileName = file.name.substring( + 0, + file.name.lastIndexOf(".") + ); + ctrl.postedFile.extension = file.name.substring( + file.name.lastIndexOf(".") + ); + ctrl.postedFile.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("hubMessages", { +modules.component("filterList", { templateUrl: - "/mix-app/views/app-portal/components/hub-messages/hub-messages.html", - controller: "HubMessagesController", - bindings: {}, -}); -app.controller("HubMessagesController", [ - "$scope", - function ($scope) { - BaseHub.call(this, $scope); - $scope.init = function () { - $scope.startConnection("portalhub"); - }; - }, -]); - -(function (angular) { - app.component("headerNav", { - templateUrl: - "/mix-app/views/app-portal/components/header-nav/headerNav.html", - controller: [ - "$rootScope", - "CommonService", - "AuthService", - function ($rootScope, commonService, authService) { - var ctrl = this; - ctrl.globalSettings = $rootScope.globalSettings; - ctrl.isInRole = $rootScope.isInRole; - this.$onInit = function () { - ctrl.isAdmin = $rootScope.isAdmin; - ctrl.localizeSettings = $rootScope.localizeSettings; - ctrl.localizeSettings.cultures = $rootScope.globalSettings.cultures; - authService.fillAuthData().then(() => { - if (authService.authentication && authService.authentication.info) { - 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 (lang, langIcon) { - ctrl.localizeSettings.lang = lang; - ctrl.localizeSettings.langIcon = langIcon; - commonService.fillAllSettings(lang).then(function () { - window.top.location = location.href; + "/mix-app/views/app-portal/components/filter-list/filter-list.html", + controller: [ + "$scope", + "$rootScope", + "ngAppSettings", + function ($scope, $rootScope, ngAppSettings) { + var ctrl = this; + ctrl.dateRange = { + fromDate: null, + toDate: null, + }; + ctrl.init = function () { + if (!ctrl.orders) { + ctrl.orders = ngAppSettings.orders; + } + ctrl.directions = ngAppSettings.directions; + ctrl.pageSizes = ngAppSettings.pageSizes; + ctrl.statuses = []; + var statuses = ngAppSettings.contentStatuses; + if (ctrl.request && ctrl.request.contentStatuses) { + statuses = ctrl.request.contentStatuses; + } + angular.forEach(statuses, function (val, i) { + ctrl.statuses.push({ + value: val, + title: val, }); - }; - 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.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 = - "/portal/file/details?folder=" + - resp.fileFolder + - "&filename=" + - resp.fileName + - resp.extension; - } else { - $rootScope.isBusy = false; - $rootScope.showErrors(["Server error"]); - } - }; - }, - ], - bindings: { - breadCrumbs: "=", - settings: "=", + }); + }; + ctrl.apply = function (pageIndex) { + $rootScope.setRequest(ctrl.request, ctrl.key); + ctrl.callback({ pageIndex: pageIndex }); + }; + ctrl.updateDate = function () { + ctrl.request.pageIndex = 0; + if (Date.parse(ctrl.dateRange.fromDate)) { + ctrl.request.fromDate = new Date( + 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 }); + }; }, - }); -})(window.angular); + ], + bindings: { + request: "=", + key: "=?", + orders: "=?", + 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 () {}; + }, + ], + bindings: {}, +}); modules.component("githubContributers", { templateUrl: @@ -9199,250 +8873,335 @@ modules.component("githubContributers", { bindings: {}, }); -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("listMixColumn", { - templateUrl: "/mix-app/views/app-portal/components/list-mix-column/view.html", +modules.component("githubReleases", { + templateUrl: "/mix-app/views/app-portal/components/github-releases/view.html", controller: [ "$rootScope", - "$scope", - "RestMixDatabaseColumnPortalService", - function ($rootScope, $scope, service) { + "$http", + function ($rootScope, $http) { var ctrl = this; - ctrl.selectedCol = null; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.$onInit = async function () { - var getDefaultAttr = await service.getDefault(); - if (getDefaultAttr.isSucceed) { - ctrl.defaultAttr = getDefaultAttr.data; - ctrl.defaultAttr.options = []; - } - }; - ctrl.addAttr = function () { - if (ctrl.columns) { - var t = angular.copy(ctrl.defaultAttr); - t.priority = ctrl.columns.length + 1; - ctrl.columns.push(t); - } - }; - ctrl.removeAttribute = async function (attr, index) { - if (confirm("Remove this column ?")) { - if (attr.id) { - $rootScope.isBusy = true; - var remove = await service.delete([attr.id]); - if (remove.isSucceed) { - ctrl.columns.splice(index, 1); - } - $rootScope.isBusy = false; - $scope.$apply(); - } else { - ctrl.columns.splice(index, 1); - } - } - }; - ctrl.addOption = function (col, index) { - var val = $("#option_" + index).val(); - col.options = col.options || []; - var opt = { - value: val, - dataType: 7, + ctrl.items = []; + ctrl.init = function () { + var req = { + method: "GET", + url: "https://api.github.com/repos/mixcore/mix.core/releases", }; - col.options.push(opt); - $("#option_" + index).val(""); + ctrl.getGithubApiResult(req); }; - ctrl.generateForm = function () { - var formHtml = document.createElement("module-form"); - formHtml.setAttribute("class", "row"); - angular.forEach(ctrl.viewmodel.attributes, function (e, i) { - var el; - var label = document.createElement("label"); - label.setAttribute("class", "form-label"); - label.setAttribute("ng-bind", "{{data.title}}"); - - switch (e.dataType) { - case "datetime": - el = document.createElement("input"); - el.setAttribute("type", "datetime-local"); - break; - - case "date": - el = document.createElement("input"); - el.setAttribute("type", "date"); - break; - - case "time": - el = document.createElement("input"); - el.setAttribute("type", "time"); - break; - - case "phonenumber": - el = document.createElement("input"); - el.setAttribute("type", "tel"); - break; - - case "number": - el = document.createElement("input"); - el.setAttribute("type", "number"); - break; - - case "html": - el = document.createElement("trumbowyg"); - el.setAttribute("options", "{}"); - el.setAttribute("type", "number"); - break; - case "textarea": - el = document.createElement("textarea"); - break; - - default: - el = document.createElement("input"); - el.setAttribute("type", "text"); - formHtml.appendChild(el); - break; + ctrl.getGithubApiResult = async function (req) { + return $http(req).then( + function (resp) { + if (resp.status == "200") { + ctrl.items = resp.data; + } else { + } + }, + function (error) { + return { + isSucceed: false, + errors: [error.statusText || error.status], + }; } - el.setAttribute("ng-model", "data.jItem[" + e.name + "].value"); - el.setAttribute("placeholder", "{{$ctrl.title}}"); - formHtml.appendChild(label); - formHtml.appendChild(el); - }); - ctrl.viewmodel.formView.content = formHtml.innerHTML; - }; - - ctrl.generateName = function (col, isForce = false) { - if (isForce || !col.name) { - col.name = $rootScope.generateKeyword(col.title, "_", true, true); - } - }; - ctrl.removeAttr = function (index) { - if (ctrl.columns) { - ctrl.columns.splice(index, 1); - } - }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.columns.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.columns.splice(ctrl.dragStartIndex + 1, 1); - } - angular.forEach(ctrl.columns, function (e, i) { - e.priority = i; - }); - }; - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - }; - ctrl.showReferences = function (col) { - ctrl.colRef = col; - $("#modal-navs").modal("show"); - }; - ctrl.referenceCallback = function (selected) { - if (selected && selected.length) { - ctrl.colRef.reference = selected; - ctrl.colRef.referenceId = selected[0].id; - } - $("#modal-navs").modal("hide"); + ); }; }, ], - bindings: { - header: "=", - columns: "=", - removeAttributes: "=", - }, + bindings: {}, }); -modules.component("mainSideBar", { - templateUrl: - "/mix-app/views/app-portal/components/main-side-bar/main-side-bar.html", +modules.component("googleAnalytic", { + templateUrl: "/mix-app/views/app-portal/components/google-analytic/view.html", + bindings: {}, controller: [ "$rootScope", - "$scope", - "ngAppSettings", - "TranslatorService", "ApiService", "CommonService", - function ( - $rootScope, - $scope, - ngAppSettings, - translatorService, - apiService, - commonService - ) { + function ($rootScope, apiService, commonService) { var ctrl = this; - ctrl.items = []; ctrl.init = function () { - var routes = JSON.parse($("#portal-menus").val()); - ctrl.items = routes.data; + if (gapi) { + gapi.analytics.ready(function () { + if ($rootScope.localizeSettings.data.Google_Client_Id) { + /** + * Authorize the user immediately if the user has already granted access. + * If no access has been created, render an authorize button inside the + * element with the ID "embed-api-auth-container". + */ + gapi.analytics.auth.authorize({ + container: "embed-api-auth-container", + //REPLACE WITH YOUR CLIENT ID + clientid: $rootScope.localizeSettings.data.Google_Client_Id, + }); + + /** + * Create a ViewSelector for the first view to be rendered inside of an + * element with the id "view-selector-1-container". + */ + var viewSelector1 = new gapi.analytics.ViewSelector({ + container: "view-selector-1-container", + }); + + /** + * Create a ViewSelector for the second view to be rendered inside of an + * element with the id "view-selector-2-container". + */ + var viewSelector2 = new gapi.analytics.ViewSelector({ + container: "view-selector-2-container", + }); + + /** + * Create a new ActiveUsers instance to be rendered inside of an + * element with the id "active-users-container" and poll for changes every + * five seconds. + */ + var activeUsers = new gapi.analytics.ext.ActiveUsers({ + container: "active-users-container", + pollingInterval: 5, + }); + /** + * Add CSS animation to visually show the when users come and go. + */ + activeUsers.once("success", function () { + var element = this.container.firstChild; + var timeout; + + this.on("change", function (data) { + var element = this.container.firstChild; + var animationClass = + data.delta > 0 ? "is-increasing" : "is-decreasing"; + element.className += " " + animationClass; + + clearTimeout(timeout); + timeout = setTimeout(function () { + element.className = element.className.replace( + / is-(increasing|decreasing)/g, + "" + ); + }, 3000); + }); + }); + + /** + * Create a ViewSelector for the second view to be rendered inside of an + * element with the id "view-selector-2-container". + */ + var viewSelector2 = new gapi.analytics.ViewSelector({ + container: "view-selector-2-container", + }); + + // Render both view selectors to the page. + // viewSelector1.execute(); + // viewSelector2.execute(); + + /** + * Create the first DataChart for top countries over the past 30 days. + * It will be rendered inside an element with the id "chart-1-container". + */ + var dataChart1 = new gapi.analytics.googleCharts.DataChart({ + query: { + // ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, + metrics: "ga:sessions", + dimensions: "ga:date", + "start-date": "30daysAgo", + "end-date": "yesterday", + }, + chart: { + container: "chart-1-container", + type: "LINE", + options: { + width: "95%", + legendTextStyle: { color: "#333" }, + titleTextStyle: { color: "#333" }, + backgroundColor: { fill: "transparent" }, + hAxis: { + textStyle: { color: "#333" }, + }, + vAxis: { + textStyle: { color: "#333" }, + }, + series: { + 0: { + color: + $rootScope.globalSettings.portalThemeSettings + .primaryColor, + }, + 1: { color: "#e7711b" }, + 2: { color: "#f1ca3a" }, + 3: { color: "#6f9654" }, + 4: { color: "#1c91c0" }, + 5: { color: "#43459d" }, + }, + }, + }, + }); + + /** + * Create the second DataChart for top countries over the past 30 days. + * It will be rendered inside an element with the id "chart-2-container". + */ + var dataChart2 = new gapi.analytics.googleCharts.DataChart({ + query: { + // ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, + metrics: "ga:sessions", + dimensions: "ga:country", + "start-date": "90daysAgo", + "end-date": "yesterday", + "max-results": 6, + sort: "-ga:sessions", + }, + chart: { + container: "chart-2-container", + type: "GEO", + options: { + width: "95%", + pieHole: 4 / 9, + }, + }, + }); + + dataChart1 + .set({ + query: { + ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, + }, + }) + .execute(); + dataChart2 + .set({ + query: { + ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, + }, + }) + .execute(); + activeUsers + .set({ + ids: $rootScope.localizeSettings.data.Google_Analytic_Ids, + }) + .execute(); + + // /** + // * Update the first dataChart when the first view selecter is changed. + // */ + // viewSelector1.on('change', function (ids) { + // dataChart1.set({ query: { ids: ids } }).execute(); + // // Start tracking active users for this view. + // activeUsers.set({ ids: ids }).execute(); + // }); + + // /** + // * Update the first dataChart when the first view selecter is changed. + // */ + // viewSelector2.on('change', function (ids) { + // dataChart2.set({ query: { ids: ids } }).execute(); + // // Start tracking active users for this view. + // activeUsers.set({ ids: ids }).execute(); + // }); + + // /** + // * Update the second dataChart when the second view selecter is changed. + // */ + // viewSelector2.on('change', function (ids) { + // dataChart2.set({ query: { ids: ids } }).execute(); + // }); + } + }); + } }; }, ], - bindings: {}, }); -modules.component("mainSideBarDynamic", { - templateUrl: - "/mix-app/views/app-portal/components/main-side-bar-dynamic/main-side-bar-dynamic.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "CommonService", - "TranslatorService", - "AuthService", - function ( - $rootScope, - $scope, - ngAppSettings, - commonService, - translatorService, - authService - ) { - var ctrl = this; - ctrl.init = function () { - commonService.getPermissions().then(function (response) { - if (response && response.isSucceed) { - ctrl.isInit = true; - ctrl.roles = response.data; - if (ctrl.roles.data) { - ctrl.role = ctrl.roles.data[0]; +(function (angular) { + app.component("headerNav", { + templateUrl: + "/mix-app/views/app-portal/components/header-nav/headerNav.html", + controller: [ + "$rootScope", + "CommonService", + "AuthService", + function ($rootScope, commonService, authService) { + var ctrl = this; + ctrl.globalSettings = $rootScope.globalSettings; + ctrl.isInRole = $rootScope.isInRole; + this.$onInit = function () { + ctrl.isAdmin = $rootScope.isAdmin; + ctrl.localizeSettings = $rootScope.localizeSettings; + ctrl.localizeSettings.cultures = $rootScope.globalSettings.cultures; + authService.fillAuthData().then(() => { + if (authService.authentication && authService.authentication.info) { + 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 (lang, langIcon) { + ctrl.localizeSettings.lang = lang; + ctrl.localizeSettings.langIcon = langIcon; + commonService.fillAllSettings(lang).then(function () { + 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.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 = + "/portal/file/details?folder=" + + resp.fileFolder + + "&filename=" + + resp.fileName + + resp.extension; + } else { $rootScope.isBusy = false; - $scope.$apply(); + $rootScope.showErrors(["Server error"]); } - }); - }; + }; + }, + ], + bindings: { + breadCrumbs: "=", + settings: "=", }, - ], - bindings: { - roles: "=", - activedRole: "=", - translate: "&", - }, + }); +})(window.angular); + +modules.component("hubMessages", { + templateUrl: + "/mix-app/views/app-portal/components/hub-messages/hub-messages.html", + controller: "HubMessagesController", + bindings: {}, }); +app.controller("HubMessagesController", [ + "$scope", + function ($scope) { + BaseHub.call(this, $scope); + $scope.init = function () { + $scope.startConnection("portalhub"); + }; + }, +]); modules.component("jsonBuilder", { templateUrl: "/mix-app/views/app-portal/components/json-builder/view.html", @@ -9632,30 +9391,234 @@ modules.component("jsonBuilder", { item.showMenu = false; ctrl.update(); }; - ctrl.addArray = function (item) { - var obj = angular.copy(ctrl.templates[2]); - obj.name = "a" + (item.columns[0].items.length + 1); - item.columns[0].items.push(obj); - item.showMenu = false; - ctrl.update(); + ctrl.addArray = function (item) { + var obj = angular.copy(ctrl.templates[2]); + obj.name = "a" + (item.columns[0].items.length + 1); + item.columns[0].items.push(obj); + item.showMenu = false; + ctrl.update(); + }; + 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.update(); + }; + + ctrl.remove = function (index, list) { + if (confirm("Remove this")) { + list.items.splice(index, 1); + ctrl.update(); + } + }; + }, + ], +}); + +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("listMixColumn", { + templateUrl: "/mix-app/views/app-portal/components/list-mix-column/view.html", + controller: [ + "$rootScope", + "$scope", + "RestMixDatabaseColumnPortalService", + function ($rootScope, $scope, service) { + var ctrl = this; + ctrl.selectedCol = null; + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.$onInit = async function () { + var getDefaultAttr = await service.getDefault(); + if (getDefaultAttr.isSucceed) { + ctrl.defaultAttr = getDefaultAttr.data; + ctrl.defaultAttr.options = []; + } + }; + ctrl.addAttr = function () { + if (ctrl.columns) { + var t = angular.copy(ctrl.defaultAttr); + t.priority = ctrl.columns.length + 1; + ctrl.columns.push(t); + } + }; + ctrl.removeAttribute = async function (attr, index) { + if (confirm("Remove this column ?")) { + if (attr.id) { + $rootScope.isBusy = true; + var remove = await service.delete([attr.id]); + if (remove.isSucceed) { + ctrl.columns.splice(index, 1); + } + $rootScope.isBusy = false; + $scope.$apply(); + } else { + ctrl.columns.splice(index, 1); + } + } + }; + ctrl.addOption = function (col, index) { + var val = $("#option_" + index).val(); + col.options = col.options || []; + var opt = { + value: val, + dataType: 7, + }; + col.options.push(opt); + $("#option_" + index).val(""); + }; + ctrl.generateForm = function () { + var formHtml = document.createElement("module-form"); + formHtml.setAttribute("class", "row"); + angular.forEach(ctrl.viewmodel.attributes, function (e, i) { + var el; + var label = document.createElement("label"); + label.setAttribute("class", "form-label"); + label.setAttribute("ng-bind", "{{data.title}}"); + + switch (e.dataType) { + case "datetime": + el = document.createElement("input"); + el.setAttribute("type", "datetime-local"); + break; + + case "date": + el = document.createElement("input"); + el.setAttribute("type", "date"); + break; + + case "time": + el = document.createElement("input"); + el.setAttribute("type", "time"); + break; + + case "phonenumber": + el = document.createElement("input"); + el.setAttribute("type", "tel"); + break; + + case "number": + el = document.createElement("input"); + el.setAttribute("type", "number"); + break; + + case "html": + el = document.createElement("trumbowyg"); + el.setAttribute("options", "{}"); + el.setAttribute("type", "number"); + break; + + case "textarea": + el = document.createElement("textarea"); + break; + + default: + el = document.createElement("input"); + el.setAttribute("type", "text"); + formHtml.appendChild(el); + break; + } + el.setAttribute("ng-model", "data.jItem[" + e.name + "].value"); + el.setAttribute("placeholder", "{{$ctrl.title}}"); + formHtml.appendChild(label); + formHtml.appendChild(el); + }); + ctrl.viewmodel.formView.content = formHtml.innerHTML; + }; + + ctrl.generateName = function (col, isForce = false) { + if (isForce || !col.name) { + col.name = $rootScope.generateKeyword(col.title, "_", true, true); + } + }; + ctrl.removeAttr = function (index) { + if (ctrl.columns) { + ctrl.columns.splice(index, 1); + } + }; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.columns.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.columns.splice(ctrl.dragStartIndex + 1, 1); + } + angular.forEach(ctrl.columns, function (e, i) { + e.priority = i; + }); + }; + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; }; - 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.update(); + ctrl.showReferences = function (col) { + ctrl.colRef = col; + $("#modal-navs").modal("show"); }; - - ctrl.remove = function (index, list) { - if (confirm("Remove this")) { - list.items.splice(index, 1); - ctrl.update(); + ctrl.referenceCallback = function (selected) { + if (selected && selected.length) { + ctrl.colRef.reference = selected; + ctrl.colRef.referenceId = selected[0].id; } + $("#modal-navs").modal("hide"); + }; + }, + ], + bindings: { + header: "=", + columns: "=", + removeAttributes: "=", + }, +}); + +modules.component("mainSideBar", { + templateUrl: + "/mix-app/views/app-portal/components/main-side-bar/main-side-bar.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "TranslatorService", + "ApiService", + "CommonService", + function ( + $rootScope, + $scope, + ngAppSettings, + translatorService, + apiService, + commonService + ) { + var ctrl = this; + ctrl.items = []; + ctrl.init = function () { + var routes = JSON.parse($("#portal-menus").val()); + ctrl.items = routes.data; }; }, ], + bindings: {}, }); modules.component("mainSideBarItem", { @@ -9692,10 +9655,214 @@ modules.component("mainSideBarItemDynamic", { }, ], bindings: { - iconSize: "=", - linkStyle: "=", - itemStyle: "=", - item: "=", + iconSize: "=", + linkStyle: "=", + itemStyle: "=", + item: "=", + }, +}); + +modules.component("mediaFileUpload", { + templateUrl: + "/mix-app/views/app-portal/components/media-file-upload/view.html", + bindings: { + header: "=?", + description: "=?", + src: "=", + srcUrl: "=", + mediaFile: "=?", + type: "=?", + folder: "=?", + auto: "=", + uploadOptions: "=?", + onDelete: "&?", + onUpdate: "&?", + onInsert: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "MediaService", + function ($rootScope, $scope, ngAppSettings, mediaService) { + var ctrl = this; + ctrl.isAdmin = $rootScope.isAdmin; + var image_placeholder = "/mix-app/assets/img/image_placeholder.jpg"; + ctrl.isImage = false; + ctrl.mediaNavs = []; + ctrl.$onInit = function () { + ctrl.autoSave = ctrl.auto === "true"; + ctrl.srcUrl = ctrl.srcUrl || image_placeholder; + ctrl.mediaFile = ctrl.mediaFile || {}; + ctrl.isImage = ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg|ico)/g); + ctrl.maxHeight = ctrl.maxHeight || "200px"; + ctrl.id = Math.floor(Math.random() * 100); + if (ctrl.uploadOptions) { + ctrl.w = ctrl.uploadOptions.width; + ctrl.h = ctrl.uploadOptions.height; + } + }; + ctrl.$doCheck = function () { + if (ctrl.src !== ctrl.srcUrl && ctrl.srcUrl != image_placeholder) { + ctrl.src = ctrl.srcUrl; + ctrl.isImage = ctrl.srcUrl + .toLowerCase() + .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); + } + }.bind(ctrl); + + ctrl.selectFile = function (files) { + if (files !== undefined && files !== null && files.length > 0) { + ctrl.formFile = files[0]; + ctrl.mediaFile.fileFolder = ctrl.folder ? ctrl.folder : "Media"; + ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; + ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; + ctrl.mediaFile.fileName = ctrl.formFile.name.substring( + 0, + ctrl.formFile.name.lastIndexOf(".") + ); + ctrl.mediaFile.extension = ctrl.formFile.name.substring( + ctrl.formFile.name.lastIndexOf(".") + ); + if ($rootScope.isImage(ctrl.formFile)) { + ctrl.canUpload = false; + mediaService.openCroppie(files[0], ctrl, ctrl.autoSave); + } else { + ctrl.mediaFile.file = ctrl.formFile; + ctrl.canUpload = true; + if (ctrl.autoSave) { + ctrl.uploadFile(ctrl.formFile); + } + // ctrl.getBase64(ctrl.formFile); + } + } + }; + + ctrl.croppieCallback = function (result) { + if (result) { + ctrl.isImage = true; + if (!ctrl.autoSave) { + ctrl.src = result; + ctrl.mediaFile.fileStream = result; + } else { + ctrl.src = result.filePath; + } + $scope.$apply(); + } else if (ctrl.formFile) { + if (ctrl.autoSave) { + ctrl.uploadFile(ctrl.formFile); + } else { + ctrl.mediaFile.file = ctrl.formFile; + ctrl.getBase64(ctrl.formFile); + } + // ctrl.uploadFile(ctrl.formFile); + } + }; + + ctrl.uploadFile = async function (file) { + if (file !== null) { + $rootScope.isBusy = true; + if (file) { + var response = await mediaService.uploadMedia( + file, + ctrl.onUploadFileProgress + ); + if (response.isSucceed) { + ctrl.media = response.data; + $rootScope.isBusy = false; + ctrl.srcUrl = response.data.filePath; + $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("mainSideBarDynamic", { + templateUrl: + "/mix-app/views/app-portal/components/main-side-bar-dynamic/main-side-bar-dynamic.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "CommonService", + "TranslatorService", + "AuthService", + function ( + $rootScope, + $scope, + ngAppSettings, + commonService, + translatorService, + authService + ) { + var ctrl = this; + ctrl.init = function () { + commonService.getPermissions().then(function (response) { + if (response && response.isSucceed) { + ctrl.isInit = true; + ctrl.roles = response.data; + if (ctrl.roles.data) { + ctrl.role = ctrl.roles.data[0]; + } + $rootScope.isBusy = false; + $scope.$apply(); + } + }); + }; + }, + ], + bindings: { + roles: "=", + activedRole: "=", + translate: "&", }, }); @@ -9760,44 +9927,6 @@ modules.component("mediaUpload", { }, }); -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 { - isSucceed: false, - errors: [error.statusText || error.status], - }; - } - ); - }; - }, - ], - bindings: {}, -}); - modules.component("mixDatabaseColumn", { templateUrl: "/mix-app/views/app-portal/components/mix-database-column/view.html", @@ -9908,6 +10037,44 @@ modules.component("mixDatabaseColumn", { ], }); +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 { + isSucceed: false, + errors: [error.statusText || error.status], + }; + } + ); + }; + }, + ], + bindings: {}, +}); + modules.component("mixDatabaseDataFilter", { templateUrl: "/mix-app/views/app-portal/components/mix-database-data-filter/view.html", @@ -9946,250 +10113,87 @@ modules.component("mixDatabaseDataFilter", { 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.isSucceed) { - 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(`/portal/page/details/${nav.id}`); - break; - case "Post": - ctrl.goToPath(`/portal/post/details/${nav.id}`); - break; - case "Module": - ctrl.goToPath(`/portal/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("mediaFileUpload", { - templateUrl: - "/mix-app/views/app-portal/components/media-file-upload/view.html", - bindings: { - header: "=?", - description: "=?", - src: "=", - srcUrl: "=", - mediaFile: "=?", - type: "=?", - folder: "=?", - auto: "=", - uploadOptions: "=?", - onDelete: "&?", - onUpdate: "&?", - onInsert: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "MediaService", - function ($rootScope, $scope, ngAppSettings, mediaService) { - var ctrl = this; - ctrl.isAdmin = $rootScope.isAdmin; - var image_placeholder = "/mix-app/assets/img/image_placeholder.jpg"; - ctrl.isImage = false; - ctrl.mediaNavs = []; - ctrl.$onInit = function () { - ctrl.autoSave = ctrl.auto === "true"; - ctrl.srcUrl = ctrl.srcUrl || image_placeholder; - ctrl.mediaFile = ctrl.mediaFile || {}; - ctrl.isImage = ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg|ico)/g); - ctrl.maxHeight = ctrl.maxHeight || "200px"; - ctrl.id = Math.floor(Math.random() * 100); - if (ctrl.uploadOptions) { - ctrl.w = ctrl.uploadOptions.width; - ctrl.h = ctrl.uploadOptions.height; - } - }; - ctrl.$doCheck = function () { - if (ctrl.src !== ctrl.srcUrl && ctrl.srcUrl != image_placeholder) { - ctrl.src = ctrl.srcUrl; - ctrl.isImage = ctrl.srcUrl - .toLowerCase() - .match(/([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|svg)/g); - } - }.bind(ctrl); - - ctrl.selectFile = function (files) { - if (files !== undefined && files !== null && files.length > 0) { - ctrl.formFile = files[0]; - ctrl.mediaFile.fileFolder = ctrl.folder ? ctrl.folder : "Media"; - ctrl.mediaFile.title = ctrl.title ? ctrl.title : ""; - ctrl.mediaFile.description = ctrl.description ? ctrl.description : ""; - ctrl.mediaFile.fileName = ctrl.formFile.name.substring( - 0, - ctrl.formFile.name.lastIndexOf(".") - ); - ctrl.mediaFile.extension = ctrl.formFile.name.substring( - ctrl.formFile.name.lastIndexOf(".") - ); - if ($rootScope.isImage(ctrl.formFile)) { - ctrl.canUpload = false; - mediaService.openCroppie(files[0], ctrl, ctrl.autoSave); - } else { - ctrl.mediaFile.file = ctrl.formFile; - ctrl.canUpload = true; - if (ctrl.autoSave) { - ctrl.uploadFile(ctrl.formFile); - } - // ctrl.getBase64(ctrl.formFile); - } + 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; } - }; - ctrl.croppieCallback = function (result) { - if (result) { - ctrl.isImage = true; - if (!ctrl.autoSave) { - ctrl.src = result; - ctrl.mediaFile.fileStream = result; - } else { - ctrl.src = result.filePath; - } + var response = await dataService.getList(ctrl.request); + if (response.isSucceed) { + ctrl.data = response.data; + ctrl.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + ctrl.isBusy = false; $scope.$apply(); - } else if (ctrl.formFile) { - if (ctrl.autoSave) { - ctrl.uploadFile(ctrl.formFile); - } else { - ctrl.mediaFile.file = ctrl.formFile; - ctrl.getBase64(ctrl.formFile); - } - // ctrl.uploadFile(ctrl.formFile); } }; - - ctrl.uploadFile = async function (file) { - if (file !== null) { - $rootScope.isBusy = true; - if (file) { - var response = await mediaService.uploadMedia( - file, - ctrl.onUploadFileProgress - ); - if (response.isSucceed) { - ctrl.media = response.data; - $rootScope.isBusy = false; - ctrl.srcUrl = response.data.filePath; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - } - } else { - return null; + ctrl.edit = function (nav) { + switch (ctrl.type) { + case "Page": + ctrl.goToPath(`/portal/page/details/${nav.id}`); + break; + case "Post": + ctrl.goToPath(`/portal/post/details/${nav.id}`); + break; + case "Module": + ctrl.goToPath(`/portal/module/details/${nav.id}`); + break; } }; - 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]); - }; + 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 { - return null; + if (!nav.isActive) { + angular.forEach(ctrl.data.items, (element) => { + element.isActive = false; + }); + } + current.isActive = !nav.isActive; } }; - ctrl.onUploadFileProgress = function (progress) { - ctrl.progress = progress; + 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; + } }; }, ], @@ -10528,26 +10532,146 @@ modules.component("mixDatabaseDataValueEditor", { // angular.element(e).triggerHandler('click'); // $location.url('/portal/mix-database-data/details?dataId='+ item.id +'&mixDatabaseId=' + item.mixDatabaseId+'&parentType=' + item.parentType+'&parentId=' + item.parentId); }; - - ctrl.removeRefData = async function (nav) { + + ctrl.removeRefData = async function (nav) { + $rootScope.showConfirm( + ctrl, + "removeRefDataConfirmed", + [nav], + null, + "Remove", + "Deleted data will not able to recover, are you sure you want to delete this item?" + ); + }; + ctrl.removeRefDataConfirmed = async function (nav) { + $rootScope.isBusy = true; + var result = await navService.delete([ + nav.parentId, + nav.parentType, + nav.id, + ]); + if (result.isSucceed) { + $rootScope.removeObjectByKey(ctrl.refData, "id", nav.id); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + }, + ], +}); + +modules.component("mixDatabaseNavData", { + templateUrl: + "/mix-app/views/app-portal/components/mix-database-nav-data/view.html", + bindings: { + nav: "=", + parentId: "=", + parentType: "=", + onUpdate: "&?", + onDelete: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "RestRelatedAttributeDataPortalService", + "RestMixDatabaseDataPortalService", + function ($rootScope, $scope, ngAppSettings, navService, dataService) { + var ctrl = this; + ctrl.data = null; + ctrl.selected = null; + ctrl.navRequest = angular.copy(ngAppSettings.request); + ctrl.setRequest = angular.copy(ngAppSettings.request); + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.$onInit = function () { + navService + .getDefault([ctrl.parentId, ctrl.parentType, "default"]) + .then((resp) => { + ctrl.defaultData = resp.data; + ctrl.defaultData.parentId = ctrl.parentId; + ctrl.defaultData.parentType = ctrl.parentType; + ctrl.selected = angular.copy(ctrl.defaultData); + ctrl.loadData(); + }); + ctrl.navRequest.parentType = ctrl.parentType; + ctrl.navRequest.parentId = ctrl.parentId; + }; + ctrl.selectPane = function (pane) {}; + ctrl.loadData = function () { + navService.getList(ctrl.navRequest).then((resp) => { + if (resp) { + ctrl.data = resp.data; + $scope.$apply(); + } else { + if (resp) { + $rootScope.showErrors("Failed"); + } + $scope.$apply(); + } + }); + }; + ctrl.updateData = function (nav) { + ctrl.selected = nav; + var e = $(".pane-form-" + ctrl.nav.data.id)[0]; + angular.element(e).triggerHandler("click"); + // $location.url('/portal/mix-database-data/details?dataId='+ item.id +'&mixDatabaseId=' + item.mixDatabaseId+'&parentType=' + item.parentType+'&parentId=' + item.parentId); + }; + ctrl.saveData = function (data) { + $rootScope.isBusy = true; + ctrl.selected.data = data; + dataService.save(data).then((resp) => { + if (resp.isSucceed) { + ctrl.selected.dataId = resp.data.id; + ctrl.selected.mixDatabaseId = resp.data.mixDatabaseId; + ctrl.selected.mixDatabaseName = resp.data.mixDatabaseName; + ctrl.selected.attributeData = resp.data; + navService.save(ctrl.selected).then((resp) => { + if (resp.isSucceed) { + var tmp = $rootScope.findObjectByKey( + ctrl.data, + ["parentId", "parentType", "id"], + [resp.data.parentId, resp.data.parentType, resp.data.id] + ); + if (!tmp) { + ctrl.data.items.push(resp.data); + var e = $(".pane-data-" + ctrl.nav.data.id)[0]; + angular.element(e).triggerHandler("click"); + } + ctrl.selected = angular.copy(ctrl.defautData); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }); + } else { + $rootScope.showMessage("failed"); + $rootScope.isBusy = false; + $scope.$apply(); + } + }); + }; + ctrl.removeData = async function (nav) { $rootScope.showConfirm( ctrl, - "removeRefDataConfirmed", + "removeDataConfirmed", [nav], null, "Remove", "Deleted data will not able to recover, are you sure you want to delete this item?" ); }; - ctrl.removeRefDataConfirmed = async function (nav) { + ctrl.removeDataConfirmed = async function (nav) { $rootScope.isBusy = true; - var result = await navService.delete([ - nav.parentId, - nav.parentType, - nav.id, - ]); + var result = await navService.delete([nav.id]); if (result.isSucceed) { - $rootScope.removeObjectByKey(ctrl.refData, "id", nav.id); + $rootScope.removeObjectByKey(ctrl.data, "id", nav.id); $rootScope.isBusy = false; $scope.$apply(); } else { @@ -10556,6 +10680,37 @@ modules.component("mixDatabaseDataValueEditor", { $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(); + }); + }; }, ], }); @@ -10682,262 +10837,91 @@ modules.component("mixDatabaseForm", { ctrl.reload = async function () { ctrl.mixDatabaseData = angular.copy(ctrl.defaultData); - }; - ctrl.loadSelected = function () { - if (ctrl.selectedList.data.length) { - ctrl.mixDatabaseData = ctrl.selectedList.data[0]; - ctrl.mixDatabaseData.mixDatabaseId = ctrl.mixDatabaseId; - ctrl.mixDatabaseData.mixDatabaseName = ctrl.mixDatabaseName; - ctrl.mixDatabaseData.parentId = ctrl.parentId; - ctrl.mixDatabaseData.parentType = ctrl.parentType; - } - }; - ctrl.submit = async function () { - if (ctrl.validate()) { - ctrl.isBusy = true; - - var saveResult = await service.save(ctrl.mixDatabaseData); - if (saveResult.isSucceed) { - ctrl.mixDatabaseData = saveResult.data; - if (ctrl.saveSuccess) { - ctrl.saveSuccess({ data: ctrl.mixDatabaseData }); - } - ctrl.isBusy = false; - $rootScope.showMessage("success"); - $scope.$apply(); - } else { - ctrl.isBusy = false; - if (saveResult) { - $rootScope.showErrors(saveResult.errors); - } - $scope.$apply(); - } - } - }; - ctrl.validate = function () { - var isValid = true; - ctrl.errors = []; - angular.forEach(ctrl.columns, function (column) { - if (column.regex) { - var regex = RegExp(column.regex, "g"); - isValid = regex.test(ctrl.mixDatabaseData.obj[column.name]); - if (!isValid) { - ctrl.errors.push(`${column.name} is not match Regex`); - } - } - if (!isValid) { - $rootScope.showErrors(ctrl.errors); - } - if (isValid && column.isEncrypt) { - ctrl.mixDatabaseData.obj[column.name] = $rootScope.encrypt( - ctrl.mixDatabaseData.obj[column.name] - ); - } - }); - return isValid; - }; - ctrl.showContentFilter = function ($event) { - $rootScope.showContentFilter(ctrl.loadSelectedLink); - }; - ctrl.loadSelectedLink = function (data, type) { - if (data) { - ctrl.mixDatabaseData.obj.target_id = data.id; - ctrl.mixDatabaseData.obj.title = data.title; - ctrl.mixDatabaseData.obj.type = type; - ctrl.mixDatabaseData.obj.uri = data.detailsUrl; - } - }; - ctrl.filterData = function (attributeName) { - if (ctrl.mixDatabaseData) { - var attr = $rootScope.findObjectByKey( - ctrl.mixDatabaseData.obj, - "mixDatabaseColumnName", - attributeName - ); - if (!attr) { - attr = angular.copy( - $rootScope.findObjectByKey( - ctrl.defaultData.data, - "mixDatabaseColumnName", - attributeName - ) - ); - mixDatabaseColumn; - ctrl.mixDatabaseData.obj.push(attr); - } - return attr; - } - }; - }, - ], -}); - -modules.component("mixDatabaseNavs", { - templateUrl: - "/mix-app/views/app-portal/components/mix-database-navs/view.html", - bindings: { - parentId: "=", - parentType: "=", - mixDatabaseNavs: "=?", - onUpdate: "&?", - onDelete: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "RestRelatedMixDatabasePortalService", - "RestMixDatabasePortalService", - function ($rootScope, $scope, ngAppSettings, navService, setService) { - var ctrl = this; - ctrl.mixDatabaseNavs = ctrl.mixDatabaseNavs || []; - ctrl.selected = {}; - ctrl.defaultData = null; - ctrl.navRequest = angular.copy(ngAppSettings.request); - ctrl.setRequest = angular.copy(ngAppSettings.request); - - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.$onInit = function () { - // ctrl.setRequest.type = ctrl.parentType; - navService.getDefault().then((resp) => { - resp.parentId = ctrl.parentId; - resp.parentType = ctrl.parentType; - ctrl.defaultData = resp; - ctrl.loadData(); - }); - }; - ctrl.goToPath = $rootScope.goToPath; - ctrl.selectPane = function (pane) {}; - ctrl.loadData = async function () { - // Load attr set navs if not in input - if (!ctrl.mixDatabaseNavs) { - ctrl.navRequest.parentType = ctrl.parentType; - ctrl.navRequest.parentId = ctrl.parentId; - var resp = await navService.getList(ctrl.navRequest); - if (resp) { - angular.forEach(resp.data.items, (e) => { - e.isActived = true; - ctrl.mixDatabaseNavs.push(e); - }); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - } - } else { - angular.forEach(ctrl.mixDatabaseNavs, (e) => { - e.isActived = true; - }); - } - - var setResult = await setService.getList(ctrl.setRequest); - if (setResult) { - angular.forEach(setResult.data.items, (element) => { - var e = $rootScope.findObjectByKey( - ctrl.mixDatabaseNavs, - "mixDatabaseId", - element.id - ); - if (!e) { - e = angular.copy(ctrl.defaultData); - e.status = "Published"; - e.mixDatabaseId = element.id; - e.specificulture = navService.lang; - e.data = element; - e.isActived = false; - ctrl.mixDatabaseNavs.push(e); - } - }); - } else { - if (setResult) { - $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); - } - }; - - 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.isSucceed) { - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; + }; + ctrl.loadSelected = function () { + if (ctrl.selectedList.data.length) { + ctrl.mixDatabaseData = ctrl.selectedList.data[0]; + ctrl.mixDatabaseData.mixDatabaseId = ctrl.mixDatabaseId; + ctrl.mixDatabaseData.mixDatabaseName = ctrl.mixDatabaseName; + ctrl.mixDatabaseData.parentId = ctrl.parentId; + ctrl.mixDatabaseData.parentType = ctrl.parentType; } }; + ctrl.submit = async function () { + if (ctrl.validate()) { + ctrl.isBusy = true; - ctrl.active = async function (nav) { - $rootScope.isBusy = true; - var result; - result = await navService.save(nav); - if (result && result.isSucceed) { - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); + var saveResult = await service.save(ctrl.mixDatabaseData); + if (saveResult.isSucceed) { + ctrl.mixDatabaseData = saveResult.data; + if (ctrl.saveSuccess) { + ctrl.saveSuccess({ data: ctrl.mixDatabaseData }); + } + ctrl.isBusy = false; + $rootScope.showMessage("success"); + $scope.$apply(); + } else { + ctrl.isBusy = false; + if (saveResult) { + $rootScope.showErrors(saveResult.errors); + } + $scope.$apply(); + } } }; - - ctrl.update = function (data) { - ctrl.onUpdate({ - data: data, + ctrl.validate = function () { + var isValid = true; + ctrl.errors = []; + angular.forEach(ctrl.columns, function (column) { + if (column.regex) { + var regex = RegExp(column.regex, "g"); + isValid = regex.test(ctrl.mixDatabaseData.obj[column.name]); + if (!isValid) { + ctrl.errors.push(`${column.name} is not match Regex`); + } + } + if (!isValid) { + $rootScope.showErrors(ctrl.errors); + } + if (isValid && column.isEncrypt) { + ctrl.mixDatabaseData.obj[column.name] = $rootScope.encrypt( + ctrl.mixDatabaseData.obj[column.name] + ); + } }); + return isValid; }; - - ctrl.delete = function (data) { - ctrl.onDelete({ - data: data, - }); + ctrl.showContentFilter = function ($event) { + $rootScope.showContentFilter(ctrl.loadSelectedLink); }; - - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - ctrl.minPriority = ctrl.mixDatabaseNavs[0].priority; + ctrl.loadSelectedLink = function (data, type) { + if (data) { + ctrl.mixDatabaseData.obj.target_id = data.id; + ctrl.mixDatabaseData.obj.title = data.title; + ctrl.mixDatabaseData.obj.type = type; + ctrl.mixDatabaseData.obj.uri = data.detailsUrl; + } }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.mixDatabaseNavs.splice(ctrl.dragStartIndex + 1, 1); + ctrl.filterData = function (attributeName) { + if (ctrl.mixDatabaseData) { + var attr = $rootScope.findObjectByKey( + ctrl.mixDatabaseData.obj, + "mixDatabaseColumnName", + attributeName + ); + if (!attr) { + attr = angular.copy( + $rootScope.findObjectByKey( + ctrl.defaultData.data, + "mixDatabaseColumnName", + attributeName + ) + ); + mixDatabaseColumn; + ctrl.mixDatabaseData.obj.push(attr); + } + return attr; } - 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(); - }); }; }, ], @@ -11110,9 +11094,143 @@ modules.component("mixDatabaseNavValues", { }; ctrl.removeDataConfirmed = async function (nav) { $rootScope.isBusy = true; - var result = await navService.delete([nav.id]); - if (result.isSucceed) { - $rootScope.removeObjectByKey(ctrl.data.items, "id", nav.id); + var result = await navService.delete([nav.id]); + if (result.isSucceed) { + $rootScope.removeObjectByKey(ctrl.data.items, "id", nav.id); + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showMessage("failed"); + $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"); + }; + }, + ], +}); + +modules.component("mixDatabaseNavs", { + templateUrl: + "/mix-app/views/app-portal/components/mix-database-navs/view.html", + bindings: { + parentId: "=", + parentType: "=", + mixDatabaseNavs: "=?", + onUpdate: "&?", + onDelete: "&?", + }, + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "RestRelatedMixDatabasePortalService", + "RestMixDatabasePortalService", + function ($rootScope, $scope, ngAppSettings, navService, setService) { + var ctrl = this; + ctrl.mixDatabaseNavs = ctrl.mixDatabaseNavs || []; + ctrl.selected = {}; + ctrl.defaultData = null; + ctrl.navRequest = angular.copy(ngAppSettings.request); + ctrl.setRequest = angular.copy(ngAppSettings.request); + + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.$onInit = function () { + // ctrl.setRequest.type = ctrl.parentType; + navService.getDefault().then((resp) => { + resp.parentId = ctrl.parentId; + resp.parentType = ctrl.parentType; + ctrl.defaultData = resp; + ctrl.loadData(); + }); + }; + ctrl.goToPath = $rootScope.goToPath; + ctrl.selectPane = function (pane) {}; + ctrl.loadData = async function () { + // Load attr set navs if not in input + if (!ctrl.mixDatabaseNavs) { + ctrl.navRequest.parentType = ctrl.parentType; + ctrl.navRequest.parentId = ctrl.parentId; + var resp = await navService.getList(ctrl.navRequest); + if (resp) { + angular.forEach(resp.data.items, (e) => { + e.isActived = true; + ctrl.mixDatabaseNavs.push(e); + }); + } else { + if (resp) { + $rootScope.showErrors(resp.errors); + } + } + } else { + angular.forEach(ctrl.mixDatabaseNavs, (e) => { + e.isActived = true; + }); + } + + var setResult = await setService.getList(ctrl.setRequest); + if (setResult) { + angular.forEach(setResult.data.items, (element) => { + var e = $rootScope.findObjectByKey( + ctrl.mixDatabaseNavs, + "mixDatabaseId", + element.id + ); + if (!e) { + e = angular.copy(ctrl.defaultData); + e.status = "Published"; + e.mixDatabaseId = element.id; + e.specificulture = navService.lang; + e.data = element; + e.isActived = false; + ctrl.mixDatabaseNavs.push(e); + } + }); + } else { + if (setResult) { + $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); + } + }; + + 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.isSucceed) { + $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.isSucceed) { $rootScope.isBusy = false; $scope.$apply(); } else { @@ -11121,12 +11239,49 @@ modules.component("mixDatabaseNavValues", { $scope.$apply(); } }; - ctrl.view = function (item) { - var obj = { - columns: ctrl.columns, - item: item, - }; - $rootScope.preview("mix-database-data", obj, null, "modal-lg"); + + 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(); + }); }; }, ], @@ -11342,157 +11497,6 @@ app.controller("MixNavigationController", [ }, ]); -modules.component("mixDatabaseNavData", { - templateUrl: - "/mix-app/views/app-portal/components/mix-database-nav-data/view.html", - bindings: { - nav: "=", - parentId: "=", - parentType: "=", - onUpdate: "&?", - onDelete: "&?", - }, - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "RestRelatedAttributeDataPortalService", - "RestMixDatabaseDataPortalService", - function ($rootScope, $scope, ngAppSettings, navService, dataService) { - var ctrl = this; - ctrl.data = null; - ctrl.selected = null; - ctrl.navRequest = angular.copy(ngAppSettings.request); - ctrl.setRequest = angular.copy(ngAppSettings.request); - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.$onInit = function () { - navService - .getDefault([ctrl.parentId, ctrl.parentType, "default"]) - .then((resp) => { - ctrl.defaultData = resp.data; - ctrl.defaultData.parentId = ctrl.parentId; - ctrl.defaultData.parentType = ctrl.parentType; - ctrl.selected = angular.copy(ctrl.defaultData); - ctrl.loadData(); - }); - ctrl.navRequest.parentType = ctrl.parentType; - ctrl.navRequest.parentId = ctrl.parentId; - }; - ctrl.selectPane = function (pane) {}; - ctrl.loadData = function () { - navService.getList(ctrl.navRequest).then((resp) => { - if (resp) { - ctrl.data = resp.data; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors("Failed"); - } - $scope.$apply(); - } - }); - }; - ctrl.updateData = function (nav) { - ctrl.selected = nav; - var e = $(".pane-form-" + ctrl.nav.data.id)[0]; - angular.element(e).triggerHandler("click"); - // $location.url('/portal/mix-database-data/details?dataId='+ item.id +'&mixDatabaseId=' + item.mixDatabaseId+'&parentType=' + item.parentType+'&parentId=' + item.parentId); - }; - ctrl.saveData = function (data) { - $rootScope.isBusy = true; - ctrl.selected.data = data; - dataService.save(data).then((resp) => { - if (resp.isSucceed) { - ctrl.selected.dataId = resp.data.id; - ctrl.selected.mixDatabaseId = resp.data.mixDatabaseId; - ctrl.selected.mixDatabaseName = resp.data.mixDatabaseName; - ctrl.selected.attributeData = resp.data; - navService.save(ctrl.selected).then((resp) => { - if (resp.isSucceed) { - var tmp = $rootScope.findObjectByKey( - ctrl.data, - ["parentId", "parentType", "id"], - [resp.data.parentId, resp.data.parentType, resp.data.id] - ); - if (!tmp) { - ctrl.data.items.push(resp.data); - var e = $(".pane-data-" + ctrl.nav.data.id)[0]; - angular.element(e).triggerHandler("click"); - } - ctrl.selected = angular.copy(ctrl.defautData); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); - $rootScope.isBusy = false; - $scope.$apply(); - } - }); - } else { - $rootScope.showMessage("failed"); - $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.isSucceed) { - $rootScope.removeObjectByKey(ctrl.data, "id", nav.id); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showMessage("failed"); - $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("mixSelectIcons", { templateUrl: "/mix-app/views/app-portal/components/mix-select-icons/mix-select-icons.html", @@ -11594,77 +11598,17 @@ modules.component("mixTemplateEditor", { $rootScope.isBusy = false; $scope.$apply(); } - } - } - }; - ctrl.updateTemplateContent = function (content) { - ctrl.template.content = content; - }; - ctrl.updateStyleContent = function (content) { - ctrl.template.scripts = content; - }; - ctrl.updateScriptContent = function (content) { - ctrl.template.styles = content; - }; - }, - ], -}); - -modules.component("modalBookmark", { - templateUrl: - "/mix-app/views/app-portal/components/modal-bookmark/modal-bookmark.html", - controller: [ - "$rootScope", - "$scope", - "localStorageService", - "$routeParams", - "$location", - function ( - $rootScope, - $scope, - localStorageService, - $routeParams, - $location - ) { - var ctrl = this; - ctrl.searchText = ""; - ctrl.defaultModel = { - url: "", - title: "", - }; - ctrl.bookmarks = []; - ctrl.model = null; - ctrl.$onInit = function () { - ctrl.model = angular.copy(ctrl.defaultModel); - ctrl.getCurrentUrl(); - ctrl.bookmarks = localStorageService.get("bookmarks") || []; - }; - ctrl.goToPath = function (url) { - $rootScope.goToPath(url); - $("#dlg-bookmark").modal("hide"); + } + } }; - ctrl.getCurrentUrl = function (url) { - url = url || $location.url(); - ctrl.model.url = url; - ctrl.model.title = url; + ctrl.updateTemplateContent = function (content) { + ctrl.template.content = content; }; - ctrl.removeBookmark = function (url) { - $rootScope.removeObjectByKey(ctrl.bookmarks, "url", url); - localStorageService.set("bookmarks", ctrl.bookmarks); + ctrl.updateStyleContent = function (content) { + ctrl.template.scripts = content; }; - ctrl.addBookmark = function () { - var current = $rootScope.findObjectByKey( - ctrl.bookmarks, - "url", - ctrl.model.url - ); - if (current) { - current.title = ctrl.model.title; - } else { - ctrl.bookmarks.push(ctrl.model); - } - localStorageService.set("bookmarks", ctrl.bookmarks); - ctrl.model = angular.copy(ctrl.defaultModel); + ctrl.updateScriptContent = function (content) { + ctrl.template.styles = content; }; }, ], @@ -11805,6 +11749,66 @@ modules.component("mixValueEditor", { ], }); +modules.component("modalBookmark", { + templateUrl: + "/mix-app/views/app-portal/components/modal-bookmark/modal-bookmark.html", + controller: [ + "$rootScope", + "$scope", + "localStorageService", + "$routeParams", + "$location", + function ( + $rootScope, + $scope, + localStorageService, + $routeParams, + $location + ) { + var ctrl = this; + ctrl.searchText = ""; + ctrl.defaultModel = { + url: "", + title: "", + }; + ctrl.bookmarks = []; + ctrl.model = null; + ctrl.$onInit = function () { + ctrl.model = angular.copy(ctrl.defaultModel); + ctrl.getCurrentUrl(); + ctrl.bookmarks = localStorageService.get("bookmarks") || []; + }; + ctrl.goToPath = function (url) { + $rootScope.goToPath(url); + $("#dlg-bookmark").modal("hide"); + }; + ctrl.getCurrentUrl = function (url) { + url = url || $location.url(); + ctrl.model.url = url; + ctrl.model.title = url; + }; + ctrl.removeBookmark = function (url) { + $rootScope.removeObjectByKey(ctrl.bookmarks, "url", url); + localStorageService.set("bookmarks", ctrl.bookmarks); + }; + ctrl.addBookmark = function () { + var current = $rootScope.findObjectByKey( + ctrl.bookmarks, + "url", + ctrl.model.url + ); + if (current) { + current.title = ctrl.model.title; + } else { + ctrl.bookmarks.push(ctrl.model); + } + localStorageService.set("bookmarks", ctrl.bookmarks); + ctrl.model = angular.copy(ctrl.defaultModel); + }; + }, + ], +}); + modules.component("modalContentFilter", { templateUrl: "/mix-app/views/app-portal/components/modal-content-filter/modal-content-filter.html", @@ -11893,81 +11897,216 @@ modules.component("modalContentFilter", { ctrl.goToPath(`/portal/module/details/${nav.id}`); break; } - }; - ctrl.loadModules = async function () { - $rootScope.isBusy = true; - var response = await moduleService.getList(ctrl.request); - if (response.isSucceed) { - ctrl.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + }; + ctrl.loadModules = async function () { + $rootScope.isBusy = true; + var response = await moduleService.getList(ctrl.request); + if (response.isSucceed) { + ctrl.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + ctrl.loadPosts = async function () { + $rootScope.isBusy = true; + var response = await postService.getList(ctrl.request); + if (response.isSucceed) { + ctrl.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + ctrl.loadPages = async function () { + $rootScope.isBusy = true; + var response = await pageService.getList(ctrl.request); + if (response.isSucceed) { + ctrl.data = response.data; + $rootScope.isBusy = false; + $scope.$apply(); + } else { + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + ctrl.select = function (nav) { + var current = $rootScope.findObjectByKey(ctrl.data.items, "id", nav.id); + if (!nav.isActive && ctrl.callback) { + ctrl.callback({ + nav: nav, + type: ctrl.type, + }); + } + 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("modalHelper", { + templateUrl: + "/mix-app/views/app-portal/components/modal-helper/modal-helper.html", + bindings: { + url: "=?", + title: "=?", + }, + controller: [ + "$rootScope", + "$scope", + "localStorageService", + "$routeParams", + "$location", + "$sce", + function ( + $rootScope, + $scope, + localStorageService, + $routeParams, + $location, + $sce + ) { + var ctrl = this; + ctrl.$onInit = function () { + $("#dev-helper-modal").on("shown.bs.modal", function () { + if ($rootScope.helperUrl) { + ctrl.trustedUrl = $sce.trustAsResourceUrl($rootScope.helperUrl); + ctrl.title = "Developer Document"; + } else { + ctrl.loadHelperUrl(); + ctrl.title = "Developer Document"; + } + $rootScope.helperUrl = null; + $scope.$apply(); + }); + }; + ctrl.loadHelperUrl = function () { + var portalUrl = $location.url(); + // var portalabsUrl = $location.absUrl(); + var defaultUrl = "//docs.mixcore.org"; + ctrl.trustedUrl = $sce.trustAsResourceUrl(defaultUrl); + + if (portalUrl.startsWith("/portal")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-administration-screens" + ); + } + if ( + portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=2") + ) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-navigation" + ); + } + if (portalUrl.startsWith("/portal/post")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-writing-posts" + ); + } + if (portalUrl.startsWith("/portal/page")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-page" + ); + } + if (portalUrl.startsWith("/portal/module")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-module" + ); + } + if (portalUrl.startsWith("/portal/mix-database")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-database" + ); + } + if ( + portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=7") + ) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-category" + ); + } + if ( + portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=8") + ) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-tag" + ); + } + if (portalUrl.startsWith("/portal/media")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-media" + ); } - }; - ctrl.loadPosts = async function () { - $rootScope.isBusy = true; - var response = await postService.getList(ctrl.request); - if (response.isSucceed) { - ctrl.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + if (portalUrl.startsWith("/portal/file")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-file" + ); } - }; - ctrl.loadPages = async function () { - $rootScope.isBusy = true; - var response = await pageService.getList(ctrl.request); - if (response.isSucceed) { - ctrl.data = response.data; - $rootScope.isBusy = false; - $scope.$apply(); - } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); + if (portalUrl.startsWith("/portal/user")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-user" + ); } - }; - ctrl.select = function (nav) { - var current = $rootScope.findObjectByKey(ctrl.data.items, "id", nav.id); - if (!nav.isActive && ctrl.callback) { - ctrl.callback({ - nav: nav, - type: ctrl.type, - }); + if (portalUrl.startsWith("/portal/theme")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-theme" + ); } - if (ctrl.isMultiple) { - current.isActive = !current.isActive; - } else { - if (!nav.isActive) { - angular.forEach(ctrl.data.items, (element) => { - element.isActive = false; - }); - } - current.isActive = !nav.isActive; + if (portalUrl.startsWith("/portal/app-settings")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-app-settings" + ); } - }; - 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; + if (portalUrl.startsWith("/portal/configuration")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-configuration" + ); + } + if (portalUrl.startsWith("/portal/my-profile")) { + ctrl.trustedUrl = $sce.trustAsResourceUrl( + defaultUrl + "/basic-usage-users-profile" + ); } + + // switch (portalUrl) { + // case '/portal': + // default: + // ctrl.trustedUrl = $sce.trustAsResourceUrl(defaultUrl); + // break; + // } }; }, ], @@ -12515,157 +12654,22 @@ modules.component("modalNavPages", { $rootScope.isBusy = false; $scope.$apply(); } else { - $rootScope.showErrors(response.errors); - $rootScope.isBusy = false; - $scope.$apply(); - } - }; - ctrl.saveSelected = function () { - ctrl.selected = $rootScope.filterArray( - ctrl.navs, - ["isActived"], - [true] - ); - setTimeout(() => { - ctrl.save().then(() => { - ctrl.loadPages(); - }); - }, 500); - }; - }, - ], -}); - -modules.component("modalHelper", { - templateUrl: - "/mix-app/views/app-portal/components/modal-helper/modal-helper.html", - bindings: { - url: "=?", - title: "=?", - }, - controller: [ - "$rootScope", - "$scope", - "localStorageService", - "$routeParams", - "$location", - "$sce", - function ( - $rootScope, - $scope, - localStorageService, - $routeParams, - $location, - $sce - ) { - var ctrl = this; - ctrl.$onInit = function () { - $("#dev-helper-modal").on("shown.bs.modal", function () { - if ($rootScope.helperUrl) { - ctrl.trustedUrl = $sce.trustAsResourceUrl($rootScope.helperUrl); - ctrl.title = "Developer Document"; - } else { - ctrl.loadHelperUrl(); - ctrl.title = "Developer Document"; - } - $rootScope.helperUrl = null; - $scope.$apply(); - }); - }; - ctrl.loadHelperUrl = function () { - var portalUrl = $location.url(); - // var portalabsUrl = $location.absUrl(); - var defaultUrl = "//docs.mixcore.org"; - ctrl.trustedUrl = $sce.trustAsResourceUrl(defaultUrl); - - if (portalUrl.startsWith("/portal")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-administration-screens" - ); - } - if ( - portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=2") - ) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-navigation" - ); - } - if (portalUrl.startsWith("/portal/post")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-writing-posts" - ); - } - if (portalUrl.startsWith("/portal/page")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-page" - ); - } - if (portalUrl.startsWith("/portal/module")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-module" - ); - } - if (portalUrl.startsWith("/portal/mix-database")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-database" - ); - } - if ( - portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=7") - ) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-category" - ); - } - if ( - portalUrl.startsWith("/portal/mix-database-data/list?mixDatabaseId=8") - ) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-tag" - ); - } - if (portalUrl.startsWith("/portal/media")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-media" - ); - } - if (portalUrl.startsWith("/portal/file")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-file" - ); - } - if (portalUrl.startsWith("/portal/user")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-user" - ); - } - if (portalUrl.startsWith("/portal/theme")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-theme" - ); - } - if (portalUrl.startsWith("/portal/app-settings")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-app-settings" - ); - } - if (portalUrl.startsWith("/portal/configuration")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-configuration" - ); - } - if (portalUrl.startsWith("/portal/my-profile")) { - ctrl.trustedUrl = $sce.trustAsResourceUrl( - defaultUrl + "/basic-usage-users-profile" - ); - } - - // switch (portalUrl) { - // case '/portal': - // default: - // ctrl.trustedUrl = $sce.trustAsResourceUrl(defaultUrl); - // break; - // } + $rootScope.showErrors(response.errors); + $rootScope.isBusy = false; + $scope.$apply(); + } + }; + ctrl.saveSelected = function () { + ctrl.selected = $rootScope.filterArray( + ctrl.navs, + ["isActived"], + [true] + ); + setTimeout(() => { + ctrl.save().then(() => { + ctrl.loadPages(); + }); + }, 500); }; }, ], @@ -12896,6 +12900,48 @@ modules.component("modalPermission", { }, }); +modules.component("modalTemplate", { + templateUrl: "/mix-app/views/app-portal/components/modal-template/view.html", + controller: [ + "$rootScope", + "$scope", + "ngAppSettings", + "TemplateService", + function ($rootScope, $scope, ngAppSettings, service) { + var ctrl = this; + ctrl.request = angular.copy(ngAppSettings.request); + ctrl.$onInit = function () { + ctrl.modal = $("#modal-template"); + ctrl.request.status = null; + ctrl.request.pageSize = 10; + ctrl.modal.on("shown.bs.modal", function () { + ctrl.search(); + }); + }; + ctrl.search = async function (pageIndex) { + if (ctrl.request.keyword.indexOf("/") > 0) { + let params = ctrl.request.keyword.split("/"); + ctrl.request.folderType = params[0]; + ctrl.request.keyword = params[1]; + } + ctrl.request.pageIndex = pageIndex || ctrl.request.pageIndex; + $rootScope.isBusy = true; + var resp = await service.getList(ctrl.request); + if (resp && resp.isSucceed) { + ctrl.data = resp.data; + } + $rootScope.isBusy = false; + $scope.$apply(); + }; + ctrl.edit = function (item) { + let path = `/portal/template/details/${item.themeId}/${item.folderType}/${item.id}`; + ctrl.modal.modal("hide"); + $rootScope.goToPath(path); + }; + }, + ], +}); + modules.component("monacoEditor", { templateUrl: "/mix-app/views/app-portal/components/monaco-editor/view.html", bindings: { @@ -13087,48 +13133,6 @@ modules.component("monacoEditor", { ], }); -modules.component("modalTemplate", { - templateUrl: "/mix-app/views/app-portal/components/modal-template/view.html", - controller: [ - "$rootScope", - "$scope", - "ngAppSettings", - "TemplateService", - function ($rootScope, $scope, ngAppSettings, service) { - var ctrl = this; - ctrl.request = angular.copy(ngAppSettings.request); - ctrl.$onInit = function () { - ctrl.modal = $("#modal-template"); - ctrl.request.status = null; - ctrl.request.pageSize = 10; - ctrl.modal.on("shown.bs.modal", function () { - ctrl.search(); - }); - }; - ctrl.search = async function (pageIndex) { - if (ctrl.request.keyword.indexOf("/") > 0) { - let params = ctrl.request.keyword.split("/"); - ctrl.request.folderType = params[0]; - ctrl.request.keyword = params[1]; - } - ctrl.request.pageIndex = pageIndex || ctrl.request.pageIndex; - $rootScope.isBusy = true; - var resp = await service.getList(ctrl.request); - if (resp && resp.isSucceed) { - ctrl.data = resp.data; - } - $rootScope.isBusy = false; - $scope.$apply(); - }; - ctrl.edit = function (item) { - let path = `/portal/template/details/${item.themeId}/${item.folderType}/${item.id}`; - ctrl.modal.modal("hide"); - $rootScope.goToPath(path); - }; - }, - ], -}); - modules.component("navs", { templateUrl: "/mix-app/views/app-portal/components/navigations/navigations.html", @@ -13159,34 +13163,204 @@ modules.component("navs", { return ctrl.limString(item.description, ctrl.titleMaxLength || 30); } }; - 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.updateOrders = function (index) { + ctrl.data.splice(index, 1); + for (var i = 0; i < ctrl.data.length; i++) { + ctrl.data[i].priority = i + 1; + } + }; + ctrl.dropCallback = function (index, item, external, type) { + ctrl.logListEvent("dropped at", index, external, type); + for (var i = 0; i < ctrl.data.length; i++) { + ctrl.data[i].priority = i + 1; + } + // Return false here to cancel drop. Return true if you insert the item yourself. + return item; + }; + ctrl.logListEvent = function (action, index, external, type) { + var message = external ? "External " : ""; + message += type + " element was " + action + " position " + index; + }; + ctrl.goToDetails = async function (nav) { + $location.url(ctrl.detailsUrl + nav[ctrl.key]); + }; + ctrl.limString = function (str, max) { + if (str) { + return str.length > max ? str.substring(0, max) + " ..." : str; + } + }; + }, + ], +}); + +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.saveGlobalSettings( + "PortalThemeSettings", + ctrl.portalThemeSettings + ); + if (resp && resp.isSucceed) { + $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", + controller: [ + "$rootScope", + "$scope", + function ($rootScope, $scope) { + var ctrl = this; + ctrl.selectedCol = null; + ctrl.localizeSettings = $rootScope.globalSettings; + ctrl.defaultAttr = { + title: "", + name: "", + defaultValue: null, + options: [], + priority: 0, + dataType: "Text", + isGroupBy: false, + isSelect: false, + isDisplay: true, + width: 3, + columnConfigurations: { + upload: { + isCrop: false, + width: null, + height: null, + }, + }, + }; + + ctrl.addAttr = function () { + if (ctrl.columns) { + var t = angular.copy(ctrl.defaultAttr); + ctrl.columns.push(t); + } + }; + + ctrl.addOption = function (col, index) { + var val = $("#option_" + index).val(); + col.options.push(val); + $("#option_" + index).val(""); + }; + ctrl.generateForm = function () { + var formHtml = document.createElement("module-form"); + formHtml.setAttribute("class", "row"); + angular.forEach(ctrl.viewmodel.columns, function (e, i) { + var el; + var label = document.createElement("label"); + label.setAttribute("class", "control-label"); + label.setAttribute("ng-bind", "{{data.title}}"); + + switch (e.dataType) { + case "datetime": + el = document.createElement("input"); + el.setAttribute("type", "datetime-local"); + break; + + case "date": + el = document.createElement("input"); + el.setAttribute("type", "date"); + break; + + case "time": + el = document.createElement("input"); + el.setAttribute("type", "time"); + break; + + case "phonenumber": + el = document.createElement("input"); + el.setAttribute("type", "tel"); + break; + + case "integer": + el = document.createElement("input"); + el.setAttribute("type", "number"); + break; + + case "html": + el = document.createElement("quill"); + el.setAttribute("options", "{}"); + el.setAttribute("type", "number"); + break; + + case "multilinetext": + el = document.createElement("textarea"); + break; + + default: + el = document.createElement("input"); + el.setAttribute("type", "text"); + formHtml.appendChild(el); + break; + } + el.setAttribute("ng-model", "data.jItem[" + e.name + "].value"); + el.setAttribute("placeholder", "{{$ctrl.title}}"); + formHtml.appendChild(label); + formHtml.appendChild(el); + }); + ctrl.viewmodel.formView.content = formHtml.innerHTML; + }; + + ctrl.generateName = function (col) { + col.name = $rootScope.generateKeyword(col.title, "_"); }; - ctrl.dropCallback = function (index, item, external, type) { - ctrl.logListEvent("dropped at", index, external, type); - for (var i = 0; i < ctrl.data.length; i++) { - ctrl.data[i].priority = i + 1; + ctrl.removeAttr = function (index) { + if (ctrl.columns) { + ctrl.columns.splice(index, 1); } - // Return false here to cancel drop. Return true if you insert the item yourself. - return item; - }; - ctrl.logListEvent = function (action, index, external, type) { - var message = external ? "External " : ""; - message += type + " element was " + action + " position " + index; }; - ctrl.goToDetails = async function (nav) { - $location.url(ctrl.detailsUrl + nav[ctrl.key]); + ctrl.dragStart = function (index) { + ctrl.dragStartIndex = index; }; - ctrl.limString = function (str, max) { - if (str) { - return str.length > max ? str.substring(0, max) + " ..." : str; + ctrl.updateOrders = function (index) { + if (index > ctrl.dragStartIndex) { + ctrl.columns.splice(ctrl.dragStartIndex, 1); + } else { + ctrl.columns.splice(ctrl.dragStartIndex + 1, 1); } + angular.forEach(ctrl.columns, function (e, i) { + e.priority = i; + }); }; }, ], + bindings: { + header: "=", + columns: "=", + }, }); modules.component("propertiesValue", { @@ -13258,46 +13432,6 @@ modules.component("propertiesValue", { ], }); -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.saveGlobalSettings( - "PortalThemeSettings", - ctrl.portalThemeSettings - ); - if (resp && resp.isSucceed) { - $rootScope.showMessage("success", "success"); - $rootScope.isBusy = false; - $scope.$apply(); - } else { - if (resp) { - $rootScope.showErrors(resp.errors); - } - $scope.$apply(); - } - }; - }, - ], -}); - modules.component("serviceHubPortal", { templateUrl: "/mix-app/views/app-portal/components/service-hub-portal/view.html", @@ -13544,6 +13678,22 @@ 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: [ @@ -13605,152 +13755,6 @@ modules.component("urlAlias", { }, }); -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("propertiesStructure", { - templateUrl: - "/mix-app/views/app-portal/components/properties-structure/view.html", - controller: [ - "$rootScope", - "$scope", - function ($rootScope, $scope) { - var ctrl = this; - ctrl.selectedCol = null; - ctrl.localizeSettings = $rootScope.globalSettings; - ctrl.defaultAttr = { - title: "", - name: "", - defaultValue: null, - options: [], - priority: 0, - dataType: "Text", - isGroupBy: false, - isSelect: false, - isDisplay: true, - width: 3, - columnConfigurations: { - upload: { - isCrop: false, - width: null, - height: null, - }, - }, - }; - - ctrl.addAttr = function () { - if (ctrl.columns) { - var t = angular.copy(ctrl.defaultAttr); - ctrl.columns.push(t); - } - }; - - ctrl.addOption = function (col, index) { - var val = $("#option_" + index).val(); - col.options.push(val); - $("#option_" + index).val(""); - }; - ctrl.generateForm = function () { - var formHtml = document.createElement("module-form"); - formHtml.setAttribute("class", "row"); - angular.forEach(ctrl.viewmodel.columns, function (e, i) { - var el; - var label = document.createElement("label"); - label.setAttribute("class", "control-label"); - label.setAttribute("ng-bind", "{{data.title}}"); - - switch (e.dataType) { - case "datetime": - el = document.createElement("input"); - el.setAttribute("type", "datetime-local"); - break; - - case "date": - el = document.createElement("input"); - el.setAttribute("type", "date"); - break; - - case "time": - el = document.createElement("input"); - el.setAttribute("type", "time"); - break; - - case "phonenumber": - el = document.createElement("input"); - el.setAttribute("type", "tel"); - break; - - case "integer": - el = document.createElement("input"); - el.setAttribute("type", "number"); - break; - - case "html": - el = document.createElement("quill"); - el.setAttribute("options", "{}"); - el.setAttribute("type", "number"); - break; - - case "multilinetext": - el = document.createElement("textarea"); - break; - - default: - el = document.createElement("input"); - el.setAttribute("type", "text"); - formHtml.appendChild(el); - break; - } - el.setAttribute("ng-model", "data.jItem[" + e.name + "].value"); - el.setAttribute("placeholder", "{{$ctrl.title}}"); - formHtml.appendChild(label); - formHtml.appendChild(el); - }); - ctrl.viewmodel.formView.content = formHtml.innerHTML; - }; - - ctrl.generateName = function (col) { - col.name = $rootScope.generateKeyword(col.title, "_"); - }; - ctrl.removeAttr = function (index) { - if (ctrl.columns) { - ctrl.columns.splice(index, 1); - } - }; - ctrl.dragStart = function (index) { - ctrl.dragStartIndex = index; - }; - ctrl.updateOrders = function (index) { - if (index > ctrl.dragStartIndex) { - ctrl.columns.splice(ctrl.dragStartIndex, 1); - } else { - ctrl.columns.splice(ctrl.dragStartIndex + 1, 1); - } - angular.forEach(ctrl.columns, function (e, i) { - e.priority = i; - }); - }; - }, - ], - bindings: { - header: "=", - columns: "=", - }, -}); - !(function (t) { var e = {}; function i(n) {