Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed grouping functionality from front-end #37

Merged
merged 3 commits into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/components/widgets-settings/account/account.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<h5 ng-if="showLabel">{{label}}</h5>
<div class="input-group settings select-account">
<!-- <<<<<<< HEAD
<select ng-model="parentWidget.selectedAccount" ng-change="onAccountSelected()" ng-options="account.name + ' (' + formatAmount(account) + ')' for account in parentWidget.content.account_list track by account.uid" class="form-control" />
</div>
======= -->
<select ng-model="parentWidget.selectedAccount" ng-change="onAccountSelected()" ng-options="formatLabel(account) for account in parentWidget.content.account_list track by account.uid" class="form-control" />
</div>
<!-- >>>>>>> develop -->
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------
Expand All @@ -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 = ->
Expand All @@ -106,7 +61,6 @@ module.directive('settingAccountsList', () ->
scope: {
parentWidget: '='
deferred: '='
callbacks: '=?'
},
controller: 'SettingAccountsListCtrl'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,22 @@ 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
onChangeCallback: $scope.updateSettings
}]
if angular.isDefined(w.metadata.comparison_mode) && w.metadata.organization_ids.length > 1
# updates model with saved settings
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 = {}

# 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')

# 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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div widget-accounts-comparison>
<div setting-accounts-list parent-widget="widget" deferred="::accountsListDeferred" callbacks="callbacks"/>
<div setting-accounts-list parent-widget="widget" deferred="::accountsListDeferred"/>

<div ng-show="widget.isEditMode" class="edit">
<h4>Widget settings</h4>
Expand All @@ -8,7 +8,7 @@ <h4>Widget settings</h4>

<div align="right">
<button class="btn btn-default" ng-click="initSettings()">Cancel</button>
<button class="btn btn-warning" ng-click="beforeUpdateSettings()">Save</button>
<button class="btn btn-warning" ng-click="updateSettings()">Save</button>
</div>
</div>

Expand Down