From 1a9dc327b3f8e71d8608c6ba90515a1e95151996 Mon Sep 17 00:00:00 2001 From: Xaun Lopez Date: Thu, 12 Nov 2015 01:33:01 +1100 Subject: [PATCH 1/3] removed grouping functionality from front-end, connected to api update cycle Switching to and from comparison mode now triggers normal metadata update cycle, with api returning formated accounts data. The params-checkboxes settings directive also now only converts relevant data to metadata. --- .../accounts-list.directive.coffee | 45 ------------------- .../params-checkboxes.directive.coffee | 2 +- .../accounts-comparison.directive.coffee | 22 ++------- .../accounts-comparison.tmpl.html | 2 +- 4 files changed, 6 insertions(+), 65 deletions(-) diff --git a/src/components/widgets-settings/accounts-list/accounts-list.directive.coffee b/src/components/widgets-settings/accounts-list/accounts-list.directive.coffee index a18d0910..a2de2691 100644 --- a/src/components/widgets-settings/accounts-list/accounts-list.directive.coffee +++ b/src/components/widgets-settings/accounts-list/accounts-list.directive.coffee @@ -19,50 +19,6 @@ module.controller('SettingAccountsListCtrl', ($scope, ImpacWidgetsSvc) -> ImpacWidgetsSvc.updateWidgetSettings(w, false) if triggerUpdate return null - # collection wrapper for w.moveAccountToAnotherList - w.clearAccounts = (src, dst, triggerUpdate=false) -> - srcCopy = angular.copy(src) - _.forEach(srcCopy, (account) -> w.moveAccountToAnotherList(account, src, dst, triggerUpdate)) - return null - - # keeps local of src accounts for switching between grouped and ungrouped. - stashedAccounts = [] - # groups accounts by a string matcher, from a src collection, into a destination collection. - # note: src collection can be the dst collection. Src will be cleared. - w.groupAccounts = (src, dst, groupByKey, regExp) -> - grouped = [] - counter = 0 - rgx = new RegExp(regExp || /[^a-z0-9]/g) - stashedAccounts = angular.copy(src) - normalise = (str) -> str.toLowerCase().replace(rgx, "") - collectBalance = (arr) -> _.reduce(arr, (total, n) -> total + n ) - sort = -> - baseAccount = src.shift() - matcher = normalise(baseAccount[groupByKey]) - group = { name: baseAccount.account_name || baseAccount.name, uid: counter++ } - group.accounts = _.select src, (acc, index) -> - src.splice(index, 1)[0] if !!acc && normalise(acc[groupByKey]) == matcher - if group.accounts.length > 0 - group.accounts.unshift(baseAccount) - # TODO::multi-currency: support for conversions across multi-currency, multi-company accounts. - group.current_balance = collectBalance(_.map(group.accounts, (acc) -> acc.current_balance)) - group.currency = _.map(group.accounts, (acc) -> acc.currency).join('/') - grouped.push(group) - unless src.length - _.forEach(grouped, (acc) -> dst.push(acc) ) - else - sort() - sort() - - # ungroups by removing manipulated(grouped) objects (src), and restores original accounts by re-applying stashedAccounts to dst. - w.ungroupAccounts = (src, dst) -> - src.length = 0 - _.forEach(stashedAccounts, (acc) -> src.push(acc) ) - stashedAccounts = [] - - # applys comparison_mode setting data to either filter or not filter accounts on load. - initializeComparisonMode = -> $scope.callbacks.runMultiCompanyComparison() - # --------------------------------------------------------- # ### Setting definition # --------------------------------------------------------- @@ -87,7 +43,6 @@ module.controller('SettingAccountsListCtrl', ($scope, ImpacWidgetsSvc) -> w.moveAccountToAnotherList(acc,w.remainingAccounts,w.selectedAccounts,false) ) stashedAccounts = angular.copy(w.remainingAccounts) - initializeComparisonMode() if $scope.callbacks? setting.isInitialized = true setting.toMetadata = -> diff --git a/src/components/widgets-settings/params-checkboxes/params-checkboxes.directive.coffee b/src/components/widgets-settings/params-checkboxes/params-checkboxes.directive.coffee index 6b7a35a5..099bb9a2 100644 --- a/src/components/widgets-settings/params-checkboxes/params-checkboxes.directive.coffee +++ b/src/components/widgets-settings/params-checkboxes/params-checkboxes.directive.coffee @@ -12,7 +12,7 @@ module.controller('SettingParamsCheckboxesCtrl', ($scope) -> setting.toMetadata = -> param = {} - param[$scope.param] = $scope.options + param[$scope.param] = _.map $scope.options, (opt) -> { id: opt.id, value: opt.value } return param w.settings.push(setting) diff --git a/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee b/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee index df45f8f3..29761653 100644 --- a/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee +++ b/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee @@ -22,43 +22,29 @@ module.controller('WidgetAccountsComparisonCtrl', ($scope, $q, ChartFormatterSvc # -------------------------------------- w.initContext = -> $scope.isDataFound = w.content? && !_.isEmpty(w.content.complete_list) - # parameters for params-checkboxes.directive + # defines the available options for params-checkboxes.directive $scope.comparisonModeOptions = [{ id: 'compare_accounts', label: 'Compare matching accounts across your companies', value: false, onChangeCallback: $scope.multiCompanyComparisonOnChange }] + # updates model with saved settings if angular.isDefined(w.metadata.comparison_mode) && w.metadata.organization_ids.length > 1 angular.merge $scope.comparisonModeOptions, w.metadata.comparison_mode + # is this needed? $scope.movedAccount = {} - # callbacks for settings components - $scope.callbacks = {} - # applys all comparison mode params - $scope.callbacks.runMultiCompanyComparison = (isOnLoad=true) -> - _.forEach $scope.comparisonModeOptions, (option) -> option.onChangeCallback(isOnLoad) - $scope.isMultiCompanyMode = -> _.result( _.find($scope.comparisonModeOptions, 'id', 'compare_accounts'), 'value') $scope.multiCompanyComparisonOnChange = (isOnLoad=false) -> - $scope.purgeSelectedAccounts() unless isOnLoad - if $scope.isMultiCompanyMode() - w.groupAccounts(w.remainingAccounts, w.remainingAccounts, 'account_name') - else - w.ungroupAccounts(w.remainingAccounts, w.remainingAccounts, 'account_name') + $scope.updateSettings() # moves all accounts from w.selectedAccounts to w.remainingAccounts $scope.purgeSelectedAccounts = -> w.clearAccounts(w.selectedAccounts, w.remainingAccounts) - # move selected accounts & set all comparisonModeOptions to false before updating settings. - $scope.beforeUpdateSettings = -> - $scope.purgeSelectedAccounts() - _.forEach $scope.comparisonModeOptions, (option) -> option.value = false if option.value - $scope.updateSettings() - $scope.hasAccountsSelected = -> return w.selectedAccounts && w.selectedAccounts.length > 0 diff --git a/src/components/widgets/accounts-comparison/accounts-comparison.tmpl.html b/src/components/widgets/accounts-comparison/accounts-comparison.tmpl.html index a660bd8e..6648535b 100644 --- a/src/components/widgets/accounts-comparison/accounts-comparison.tmpl.html +++ b/src/components/widgets/accounts-comparison/accounts-comparison.tmpl.html @@ -8,7 +8,7 @@

Widget settings

- +
From 7d29706398cf09b3b97cd2f13b0e3c0441664e36 Mon Sep 17 00:00:00 2001 From: Xaun Lopez Date: Fri, 13 Nov 2015 08:15:55 +1100 Subject: [PATCH 2/3] fix for conditional causing error when no organisations are selected --- .../accounts-comparison/accounts-comparison.directive.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee b/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee index 29761653..41d0f74e 100644 --- a/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee +++ b/src/components/widgets/accounts-comparison/accounts-comparison.directive.coffee @@ -30,7 +30,7 @@ module.controller('WidgetAccountsComparisonCtrl', ($scope, $q, ChartFormatterSvc onChangeCallback: $scope.multiCompanyComparisonOnChange }] # updates model with saved settings - if angular.isDefined(w.metadata.comparison_mode) && w.metadata.organization_ids.length > 1 + if angular.isDefined(w.metadata.comparison_mode) && w.metadata.organization_ids? && w.metadata.organization_ids.length > 1 angular.merge $scope.comparisonModeOptions, w.metadata.comparison_mode # is this needed? $scope.movedAccount = {} From d661505a923d0aaf6c86539bf6c8460f2054efeb Mon Sep 17 00:00:00 2001 From: Xaun Lopez Date: Wed, 18 Nov 2015 16:37:23 +1100 Subject: [PATCH 3/3] cleaning ups --- .../widgets-settings/account/account.tmpl.html | 5 ----- .../accounts-list/accounts-list.directive.coffee | 1 - .../accounts-comparison.directive.coffee | 9 +-------- .../accounts-comparison/accounts-comparison.tmpl.html | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/components/widgets-settings/account/account.tmpl.html b/src/components/widgets-settings/account/account.tmpl.html index 56c3fd04..061f67b0 100644 --- a/src/components/widgets-settings/account/account.tmpl.html +++ b/src/components/widgets-settings/account/account.tmpl.html @@ -1,9 +1,4 @@
{{label}}