215 lines
10 KiB
JavaScript
215 lines
10 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by igor.samulenko on 4/29/2014.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('adminModule')
|
|
.controller('ScreenConfigurationController', ['$filter', '$modal', '$rootScope', '$scope', '$log', '$q', 'events', 'screenConfigurationModel', 'systemAlertService', 'layoutConfigurationModel', 'pwaModel',
|
|
function ($filter, $modal, $rootScope, $scope, $log, $q, events, screenConfigurationModel, systemAlertService, layoutConfigurationModel, pwaModel) {
|
|
/**
|
|
* Public functions
|
|
*/
|
|
/**
|
|
* Opens custom area editor for panel
|
|
*
|
|
* @param {PanelVO} panel
|
|
*/
|
|
$scope.showEditor = function (panel, allPanels) {
|
|
$modal.open({
|
|
templateUrl: 'views/admin/screen-configuration/custom-area-editor.html',
|
|
windowClass: 'action-blade',
|
|
controller: 'CustomAreaEditorController',
|
|
size: 'extra-lg',
|
|
resolve: {
|
|
customArea: function () {
|
|
// create copy for editor
|
|
return angular.copy(panel);
|
|
},
|
|
allPanels: function () {
|
|
return angular.copy(allPanels);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Opens custom actions editor for panel
|
|
*
|
|
* @param {PanelVO} panel
|
|
*/
|
|
$scope.showActionEditor = function (screen) {
|
|
$modal.open({
|
|
templateUrl: 'views/admin/screen-configuration/custom-action-editor.html',
|
|
windowClass: 'action-blade',
|
|
controller: 'CustomActionEditorController',
|
|
resolve: {
|
|
screenObj: function () {
|
|
// create copy for editor
|
|
return angular.copy(screen);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
$scope.onPanelMouseOver = function (screen, panel) {
|
|
screen.hoveredPanelId = panel.shortId;
|
|
};
|
|
$scope.onPanelMouseLeave = function (screen) {
|
|
screen.hoveredPanelId = '';
|
|
};
|
|
/**
|
|
*
|
|
* @param screen
|
|
*/
|
|
$scope.onRefreshMetadataClick = function (screen) {
|
|
var screenName = screen.isV2Compatible() ? screen.name : '';
|
|
$scope.dataLoading = true;
|
|
screenConfigurationModel.refreshMetadataForDatasource(screen.datasource, screenName)
|
|
.then(function () {
|
|
var additionalRequestParams = screen.isV2Compatible() ? { fromConfig: true } : angular.noop();
|
|
var screenConfigPromise = screenConfigurationModel.loadScreenConfigurationByName(screen.name, true, additionalRequestParams), availableFieldsPromise = screenConfigurationModel.loadAvailableFieldList(screen.panels[0]);
|
|
return $q.all([screenConfigPromise, availableFieldsPromise]);
|
|
})
|
|
.then(function () {
|
|
var screenLabel = $filter('i18n')('customization.screen.' + screen.name);
|
|
var message = $filter('i18n')('screenConfiguration.metadataRefreshedSuccessfully', screenLabel);
|
|
screenConfigurationModel.availableFieldsCache[screen.name] = angular.copy(screenConfigurationModel.fieldList);
|
|
populateAdditionalDataToScreens(screenConfigurationModel.screenList, true);
|
|
$scope.screens = updateScreensOrder(screenConfigurationModel.screenList);
|
|
systemAlertService.success({ text: message, clear: true, hide: 10000 });
|
|
}, function (error) {
|
|
systemAlertService.error({
|
|
text: error.data && error.data.error,
|
|
clear: false
|
|
});
|
|
}).finally(function () {
|
|
$scope.dataLoading = false;
|
|
});
|
|
};
|
|
$scope.getScreenInvalidationTooltip = function (screen) {
|
|
var issues = screen.invalidCustomizations;
|
|
if (issues) {
|
|
var issueLabels = [];
|
|
if (issues.missingSystemFields) {
|
|
issueLabels.push($filter('i18n')('customization.screen.invalidCustomization.tooltips.missingSystemFields'));
|
|
}
|
|
return $filter('i18n')('customization.screen.invalidCustomization.tooltip', issueLabels.join(', '));
|
|
}
|
|
};
|
|
$scope.refreshServerCache = function () {
|
|
$scope.dataLoading = true;
|
|
screenConfigurationModel.refreshServerCache().then(function () {
|
|
systemAlertService.success({
|
|
text: $filter('i18n')('screenConfiguration.refreshServerCacheSuccessfully'), clear: true, hide: 10000
|
|
});
|
|
}, function (error) {
|
|
systemAlertService.error({
|
|
text: error.data && error.data.error,
|
|
clear: false
|
|
});
|
|
}).finally(function () {
|
|
$scope.dataLoading = false;
|
|
});
|
|
};
|
|
/**
|
|
* Private functions
|
|
*/
|
|
/**
|
|
* Loads screen configuration
|
|
* @param {Boolean} requestData - flag that controls whether to use cached value or send server request for available fields
|
|
*/
|
|
function loadConfiguration(requestData) {
|
|
$scope.dataLoading = true;
|
|
return $q.all([
|
|
screenConfigurationModel.loadConfiguration(),
|
|
layoutConfigurationModel.loadLayout(),
|
|
screenConfigurationModel.loadAvailableFieldListForAllNewScreens(requestData)
|
|
])
|
|
.then(function () {
|
|
$scope.screens = updateScreensOrder(screenConfigurationModel.screenList);
|
|
// Do not backport below code for versions where Asset is not supported in PV
|
|
if (pwaModel.isPwaEnabled()) {
|
|
$scope.assetScreen = screenConfigurationModel.savedAssetScreen;
|
|
}
|
|
populateAdditionalDataToScreens($scope.screens, true);
|
|
})
|
|
.finally(function () {
|
|
$scope.dataLoading = false;
|
|
});
|
|
}
|
|
function getConfigurationsData(requestData) {
|
|
$scope.dataLoading = true;
|
|
loadConfiguration(requestData)
|
|
.finally(function () {
|
|
$scope.dataLoading = false;
|
|
});
|
|
}
|
|
function populateAdditionalDataToScreens(screens, validateScreen) {
|
|
screens.forEach(function (screen) {
|
|
screen.layout = layoutConfigurationModel.getLayoutFromCacheByScreenName(screen.name);
|
|
if (validateScreen && screenConfigurationModel.availableFieldsCache[screen.name]) {
|
|
checkScreenValidity(screen, screenConfigurationModel.availableFieldsCache[screen.name]);
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* Entry point
|
|
*/
|
|
var unbind1, unbind2;
|
|
function init() {
|
|
unbind1 = $rootScope.$on(events.RELOAD_APP_CONFIGURATION, getConfigurationsData);
|
|
getConfigurationsData(true);
|
|
}
|
|
unbind2 = $rootScope.$on(events.RELOAD_APP_CONFIGURATION_COMPLETED, function (e, data) {
|
|
$scope.screens = updateScreensOrder(screenConfigurationModel.screenList);
|
|
populateAdditionalDataToScreens($scope.screens, true);
|
|
if (data) {
|
|
var invalidScreen = _.find($scope.screens, { name: data.screenName }) || {};
|
|
if (invalidScreen.isV2Compatible()) {
|
|
invalidScreen.invalidCustomizations = data.invalidCustomizations;
|
|
}
|
|
}
|
|
});
|
|
$scope.$on("$destroy", function () {
|
|
console.log("destroy root scope events bound from here");
|
|
unbind1();
|
|
unbind2();
|
|
});
|
|
function updateScreensOrder(screens) {
|
|
var newScreens = [], oldScreens = screens.reduce(function (acc, screen) {
|
|
if (screen.isV2Compatible()) {
|
|
newScreens.push(screen);
|
|
}
|
|
else {
|
|
acc.push(screen);
|
|
}
|
|
return acc;
|
|
}, []);
|
|
if (newScreens.length) {
|
|
newScreens.sort(function (scrA, scrB) {
|
|
var scrApos = scrA.getScreenOrderNumber(), scrBpos = scrB.getScreenOrderNumber();
|
|
if (scrApos > scrBpos) {
|
|
return 1;
|
|
}
|
|
else if (scrApos < scrBpos) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
});
|
|
}
|
|
return newScreens.concat(oldScreens);
|
|
}
|
|
function checkScreenValidity(screen, availableFields) {
|
|
if (screen.isV2Compatible()) {
|
|
var uniqueAvailableFieldsList = screenConfigurationModel.getAvailableFieldsForScreen(screen.name, availableFields);
|
|
var missingSystemRequiredFields = uniqueAvailableFieldsList.some(function (field) {
|
|
return field.isMissingSystemRequiredField();
|
|
});
|
|
if (missingSystemRequiredFields) {
|
|
screen.invalidCustomizations = { missingSystemFields: true };
|
|
}
|
|
}
|
|
}
|
|
init();
|
|
}]);
|
|
})();
|