diff --git a/Changelog.md b/Changelog.md index 65d88647..832eb84f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,8 @@ ### v1.8.0 | 2018 - Week 10 #### Adds +- [IMPAC-793] Load dynamic generic layout templates for Bolt widgets +- [IMPAC-791] Add generic table layout template #### Fixes diff --git a/src/components/dashboard/dashboard.directive.coffee b/src/components/dashboard/dashboard.directive.coffee index 5fe2b5f9..9f706ff7 100644 --- a/src/components/dashboard/dashboard.directive.coffee +++ b/src/components/dashboard/dashboard.directive.coffee @@ -238,7 +238,7 @@ module.controller('ImpacDashboardCtrl', ($scope, $http, $q, $filter, $uibModal, return [] $scope.addWidget = (widgetTemplate) -> - params = _.pick(widgetTemplate, ['endpoint', 'name', 'width', 'metadata']) + params = _.pick(widgetTemplate, ['endpoint', 'name', 'width', 'metadata', 'layouts']) angular.element('#widget-selector').css('cursor', 'progress') angular.element('#widget-selector .section-lines .line-item').css('cursor', 'progress') diff --git a/src/components/widget/widget.directive.coffee b/src/components/widget/widget.directive.coffee index 2f90ca26..17507326 100644 --- a/src/components/widget/widget.directive.coffee +++ b/src/components/widget/widget.directive.coffee @@ -63,7 +63,7 @@ module.controller('ImpacWidgetCtrl', ($scope, $log, $q, $timeout, ImpacWidgetsSv ImpacDashboardsSvc.tick() ) -module.directive('impacWidget', ($templateCache, ImpacUtilities, ImpacWidgetsSvc) -> +module.directive('impacWidget', ($log, $templateCache, ImpacUtilities, ImpacWidgetsSvc, ImpacWidgetsTemplates, toastr) -> return { restrict: 'A', scope: { @@ -75,16 +75,22 @@ module.directive('impacWidget', ($templateCache, ImpacUtilities, ImpacWidgetsSvc }, controller: 'ImpacWidgetCtrl', link: (scope, element) -> - # initialize scope attributes # -------------------------------------- - scope.widget.isLoading = true - scope.widget.settings = [] - scope.pdfMode = false - scope.cssClass = ImpacUtilities.fetchWidgetCssClass(scope.widget) - scope.templatePath = ImpacUtilities.fetchWidgetTemplatePath(scope.widget) + onInit = -> + scope.showInfoPanel = false + scope.pdfMode = false + scope.widget.isLoading = true + scope.widget.settings = [] + # Unused so far --> + scope.widget.hasEditAbility = true + scope.widget.hasDeleteAbility = true + # <-- + + scope.cssClass = ImpacWidgetsTemplates.filename(scope.widget) + scope.templatePath = ImpacWidgetsTemplates.templatePath(scope.widget) + _handleNoTemplateFound() unless scope.templatePath - scope.showInfoPanel = false scope.isInfoPanelDisplayed = -> scope.showInfoPanel @@ -106,6 +112,14 @@ module.directive('impacWidget', ($templateCache, ImpacUtilities, ImpacWidgetsSvc ImpacWidgetsSvc.delete(scope.widget) .then(null, (e) -> scope.widget.errors = ImpacUtilities.processRailsError(e)) + _handleNoTemplateFound = -> + toastr.warning('See browser console for more details', "No template found for #{scope.widget.name}") + $log.error("No template or generic layout template found for #{scope.widget.name}, either add a custom template or blacklist the widget via the ImpacTheming service.") + scope.deleteWidget() + + onInit() + + return ,template: $templateCache.get('widget/widget.tmpl.html') } ) diff --git a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee index 6eed97c6..266730cd 100644 --- a/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee +++ b/src/components/widgets-common/chart-threshold/chart-threshold.component.coffee @@ -16,7 +16,7 @@ module.component('chartThreshold', { kpiCreateLabel: '' thresholdColor: '@' onComplete: '&?' - controller: ($timeout, $log, ImpacKpisSvc, ImpacUtilities, toastr)-> + controller: ($timeout, $log, ImpacKpisSvc, toastr)-> ctrl = this ctrl.$onInit = -> diff --git a/src/components/widgets-common/info-panel/info-panel.directive.coffee b/src/components/widgets-common/info-panel/info-panel.directive.coffee index da1c1034..131f7fe9 100644 --- a/src/components/widgets-common/info-panel/info-panel.directive.coffee +++ b/src/components/widgets-common/info-panel/info-panel.directive.coffee @@ -1,6 +1,6 @@ module = angular.module('impac.components.widgets-common.info-panel',[]) -module.directive('commonInfoPanel', ($templateCache, ImpacUtilities) -> +module.directive('commonInfoPanel', ($templateCache, ImpacWidgetsTemplates) -> return { restrict: 'A' scope: { @@ -8,7 +8,7 @@ module.directive('commonInfoPanel', ($templateCache, ImpacUtilities) -> onClose: '&' } template: $templateCache.get('widgets-common/info-panel.tmpl.html') - + link: (scope) -> w = scope.parentWidget @@ -19,7 +19,7 @@ module.directive('commonInfoPanel', ($templateCache, ImpacUtilities) -> scope.onClose() scope.getWidgetTemplateName = -> - cssClass = ImpacUtilities.fetchWidgetCssClass(w) + cssClass = ImpacWidgetsTemplates.filename(w) return "" unless cssClass cssClassArray = cssClass.split('-') diff --git a/src/components/widgets-common/top-buttons/top-buttons.directive.coffee b/src/components/widgets-common/top-buttons/top-buttons.directive.coffee index 7ef8a2ab..ef6dda82 100644 --- a/src/components/widgets-common/top-buttons/top-buttons.directive.coffee +++ b/src/components/widgets-common/top-buttons/top-buttons.directive.coffee @@ -1,5 +1,5 @@ module = angular.module('impac.components.widgets-common.top-buttons', []) -module.controller('CommonTopButtonsCtrl', ($scope, $rootScope, $log, ImpacWidgetsSvc, ImpacAssets, ImpacUtilities) -> +module.controller('CommonTopButtonsCtrl', ($scope, $rootScope, $log, ImpacWidgetsSvc, ImpacAssets) -> w = $scope.parentWidget w.isEditMode = false diff --git a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee b/src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.directive.coffee similarity index 97% rename from src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee rename to src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.directive.coffee index b214fb59..d4a9ee89 100644 --- a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.directive.coffee +++ b/src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.directive.coffee @@ -1,4 +1,4 @@ -module = angular.module('impac.components.widgets.accounts-cash-balance', []) +module = angular.module('impac.components.widgets-layouts.accounts-cash-balance', []) module.controller('WidgetAccountsCashBalanceCtrl', ($scope, $q, $timeout, $filter, ImpacTheming, ImpacAssets, ImpacWidgetsSvc, HighchartsFactory) -> w = $scope.widget diff --git a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.less b/src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.less similarity index 100% rename from src/components/widgets/accounts-cash-balance/accounts-cash-balance.less rename to src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.less diff --git a/src/components/widgets/accounts-cash-balance/accounts-cash-balance.tmpl.html b/src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.tmpl.html similarity index 100% rename from src/components/widgets/accounts-cash-balance/accounts-cash-balance.tmpl.html rename to src/components/widgets-layouts/custom/accounts-cash-balance/accounts-cash-balance.tmpl.html diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee b/src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.directive.coffee similarity index 98% rename from src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee rename to src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.directive.coffee index 107f9dc4..71275120 100644 --- a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.directive.coffee +++ b/src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.directive.coffee @@ -1,4 +1,4 @@ -module = angular.module('impac.components.widgets.accounts-cash-projection', []) +module = angular.module('impac.components.widgets-layouts.accounts-cash-projection', []) module.controller('WidgetAccountsCashProjectionCtrl', ($scope, $q, $filter, $timeout , ImpacKpisSvc, ImpacWidgetsSvc, ImpacAssets, HighchartsFactory, BoltResources) -> # == Context and Helpers ======================================================================== diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.less b/src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.less similarity index 100% rename from src/components/widgets/accounts-cash-projection/accounts-cash-projection.less rename to src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.less diff --git a/src/components/widgets/accounts-cash-projection/accounts-cash-projection.tmpl.html b/src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.tmpl.html similarity index 100% rename from src/components/widgets/accounts-cash-projection/accounts-cash-projection.tmpl.html rename to src/components/widgets-layouts/custom/accounts-cash-projection/accounts-cash-projection.tmpl.html diff --git a/src/components/widgets-layouts/table/table.directive.coffee b/src/components/widgets-layouts/table/table.directive.coffee new file mode 100644 index 00000000..15f2e920 --- /dev/null +++ b/src/components/widgets-layouts/table/table.directive.coffee @@ -0,0 +1,120 @@ +# +# Component generated by Impac! Widget Generator! +# +module = angular.module('impac.components.widgets-layouts.table', []) +module.controller('WidgetTableCtrl', ($scope, $q, $filter, ImpacWidgetsSvc) -> + + w = $scope.widget + + # Define settings + # -------------------------------------- + $scope.orgDeferred = $q.defer(); + $scope.timePeriodDeferred = $q.defer() + + settingsPromises = [ + $scope.orgDeferred.promise, + $scope.timePeriodDeferred.promise + ] + + # Configure the commonTimePeriodInfo directive + $scope.timePeriodInfoParams = { + accountingBehaviour: 'pnl' + histParams: {} + } + + # Widget specific methods + # -------------------------------------- + w.initContext = -> + $scope.table = _.get(w, 'content.table', {}) + return if _.isEmpty($scope.table.rows) + $scope.currency = _.get(w, 'metadata.currency') + $scope.timePeriodInfoParams.histParams = _.get(w, 'metadata.hist_parameters', {}) + $scope.unCollapsed = _.get(w, 'metadata.unCollapsed') || [] + $scope.ascending = true + $scope.sortedColumn = $scope.table.headers.cells[0] + $scope.colSize = $scope.table.headers.cells.length + $scope.colWidth = "#{100 / $scope.colSize}%" + return + + $scope.cellValue = (v)-> + num = parseFloat(v) + if _.isNumber(num) && !_.isNaN(num) then $filter('mnoCurrency')(v, $scope.currency) else v + + $scope.toggleCollapsed = (table, $event) -> + $event.stopPropagation() + id = table.headers.id + return unless id? + if _.find($scope.unCollapsed, ((name) -> id == name)) + $scope.unCollapsed = _.reject($scope.unCollapsed, (name) -> name == id) + else + $scope.unCollapsed.push(id) + ImpacWidgetsSvc.updateWidgetSettings(w,false) + + $scope.isCollapsed = (table) -> + id = table.headers.id + return unless id? + if _.find($scope.unCollapsed, ((name) -> id == name)) + return false + else + return true + + $scope.sort = (col, $index) -> + if $scope.sortedColumn == col + $scope.ascending = !$scope.ascending + else + $scope.ascending = true + $scope.sortedColumn = col + sortData($scope.table.rows, $index) + + sortData = (rows, colIndex)-> + rows.single = sortSingleRows(rows.single, colIndex) if rows.single + if rows.grouped + for table in rows.grouped + sortData(table.rows, colIndex) + return + + sortSingleRows = (rows, colIndex) -> + _.sortByOrder(rows, ((r)-> r.cells[colIndex]), [$scope.ascending]) + + # Mini-settings objects + # handles the saving of collapsed / uncollapsed list groups. + # -------------------------------------- + unCollapsedSetting = {} + unCollapsedSetting.initialized = false + + unCollapsedSetting.initialize = -> + unCollapsedSetting.initialized = true + + unCollapsedSetting.toMetadata = -> + {unCollapsed: $scope.unCollapsed} + + w.settings.push(unCollapsedSetting) + + # Widget is ready: can trigger the "wait for settings to be ready" + # -------------------------------------- + $scope.widgetDeferred.resolve(settingsPromises) +) +module.directive('widgetTable', -> + return { + restrict: 'A', + controller: 'WidgetTableCtrl' + } +) +module.directive('indentTableRow', -> + return { + restrict: 'A', + link: (_$scope, $element) -> + if $element.is(':first-child') + # Get list of ancestor tables up until the root table + ancestorTables = $element.closest('table').parentsUntil('#table-layout', 'table') + # Indent