This repository has been archived by the owner on May 20, 2024. It is now read-only.
History filtering #382 #449
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb7edb1
History: Added filter options
D0nPiano 0a8fc9d
Merge origin/master into historyFiltering#382
D0nPiano 2f110cc
Merge branch 'master' into historyFiltering#382
tiltec abadcdc
refactor to angular style
tiltec 798690c
save selection to separate list
tiltec 41ef79a
add tests
tiltec e4c3c94
unify and explain translations
tiltec 94af2dc
fix test
tiltec 50d5603
use gettersetter to show log entries of unknown users
tiltec cb6b247
enable user search
tiltec File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
105 changes: 104 additions & 1 deletion
105
client/app/components/group/_history/history.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,112 @@ | ||
class HistoryController { | ||
constructor() { | ||
constructor(Store, User) { | ||
"ngInject"; | ||
Object.assign(this, { | ||
Store, | ||
User, | ||
stores: {}, | ||
users: {}, | ||
types: { | ||
groups: true, | ||
stores: true, | ||
pickups: true | ||
}, | ||
filteredData: [] | ||
}); | ||
} | ||
|
||
$onInit(){ | ||
this.getAllStores(); | ||
this.getAllUsers(); | ||
this.updateFilteredData(); | ||
} | ||
|
||
update(){ | ||
this.updateFilteredData(); | ||
} | ||
|
||
updateFilteredData(){ | ||
this.filteredData = []; | ||
angular.forEach(this.data, (currentHistoryItem) => { | ||
if (this.showItem(currentHistoryItem)){ | ||
this.filteredData.push(currentHistoryItem); | ||
} | ||
}); | ||
} | ||
|
||
_showItemByStore(item){ | ||
return !(angular.isDefined(item.store) | ||
&& angular.isDefined(this.stores[item.store]) | ||
&& !this.stores[item.store].selected); | ||
} | ||
_showItemByUser(item){ | ||
if (item.users.length > 0){ | ||
let atLeastOneUserSelected = false; | ||
angular.forEach(item.users, (user) => { | ||
if (angular.isUndefined(this.users[user]) || this.users[user].selected){ | ||
atLeastOneUserSelected = true; | ||
} | ||
}); | ||
return atLeastOneUserSelected; | ||
} | ||
} | ||
_showItemByType(item){ | ||
if ((item.typus.includes("PICKUP") || item.typus.includes("SERIES")) && !this.types.pickups){ | ||
return false; | ||
} | ||
if (item.typus.includes("GROUP") && !this.types.groups){ | ||
return false; | ||
} | ||
if (item.typus.includes("STORE") && !this.types.stores){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
showItem(item){ | ||
return this._showItemByStore(item) && this._showItemByUser(item) && this._showItemByType(item); | ||
} | ||
|
||
showAllStores(bool){ | ||
angular.forEach(this.stores, (store) => { | ||
store.selected = bool; | ||
}); | ||
this.updateFilteredData(); | ||
} | ||
|
||
getAllStores(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could get rid of this function by using the values from the CurrentStores service. |
||
let stores = {}; | ||
angular.forEach(this.data, (currentHistoryItem) => { | ||
if (angular.isUndefined(stores[currentHistoryItem.store])) { | ||
this.Store.get(currentHistoryItem.store).then((data) => { | ||
data.selected = true; | ||
this.stores[currentHistoryItem.store] = data; | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
showAllUsers(bool){ | ||
angular.forEach(this.users, (user) => { | ||
user.selected = bool; | ||
}); | ||
this.updateFilteredData(); | ||
} | ||
|
||
getAllUsers(){ | ||
let users = {}; | ||
angular.forEach(this.data, (currentHistoryItem) => { | ||
angular.forEach(currentHistoryItem.users, (user) => { | ||
if (angular.isUndefined(users[user])) { | ||
this.User.get(user).then((data) => { | ||
data.selected = true; | ||
this.users[user] = data; | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
$onChanges(changes) { | ||
if (changes && changes.data) { | ||
angular.forEach(this.data, (entry) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,48 @@ | ||
<div> | ||
<div ng-repeat="entry in $ctrl.data"> | ||
<div class="filters"> | ||
<md-menu-bar> | ||
<i class="fa fa-filter" aria-hidden="true"></i> | ||
<md-menu> | ||
<button ng-click="$mdMenu.open()" translate="HISTORY.STORES"></button> | ||
<md-menu-content> | ||
<md-menu-item> | ||
<md-button ng-click="$ctrl.showAllStores(true)" translate="HISTORY.SELECT_ALL"></md-button> | ||
</md-menu-item> | ||
<md-menu-item> | ||
<md-button ng-click="$ctrl.showAllStores(false)" translate="HISTORY.SELECT_NONE"></md-button> | ||
</md-menu-item> | ||
<md-menu-divider></md-menu-divider> | ||
<md-menu-item type="checkbox" ng-click="$ctrl.update()" ng-model="store.selected" ng-repeat="store in $ctrl.stores">{{store.name}}</md-menu-item> | ||
</md-menu-content> | ||
</md-menu> | ||
<md-menu> | ||
<button ng-click="$mdMenu.open()"> | ||
Users | ||
</button> | ||
<md-menu-content> | ||
<md-menu-item> | ||
<md-button ng-click="$ctrl.showAllUsers(true)" translate="HISTORY.SELECT_ALL"></md-button> | ||
</md-menu-item> | ||
<md-menu-item> | ||
<md-button ng-click="$ctrl.showAllUsers(false)" translate="HISTORY.SELECT_NONE"></md-button> | ||
</md-menu-item> | ||
<md-menu-divider></md-menu-divider> | ||
<md-menu-item type="checkbox" ng-click="$ctrl.update()" ng-model="user.selected" ng-repeat="user in $ctrl.users">{{user.display_name}}</md-menu-item> | ||
</md-menu-content> | ||
</md-menu> | ||
<md-menu> | ||
<button ng-click="$mdMenu.open()"> | ||
Type | ||
</button> | ||
<md-menu-content> | ||
<md-menu-item type="checkbox" ng-click="$ctrl.update()" ng-model="$ctrl.types.groups">{{'HISTORY.TYPES.GROUPS' | translate}}</md-menu-item> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is recommended to use the |
||
<md-menu-item type="checkbox" ng-click="$ctrl.update()" ng-model="$ctrl.types.stores">{{'HISTORY.TYPES.STORES' | translate}}</md-menu-item> | ||
<md-menu-item type="checkbox" ng-click="$ctrl.update()" ng-model="$ctrl.types.pickups">{{'HISTORY.TYPES.PICKUPS' | translate}}</md-menu-item> | ||
</md-menu-content> | ||
</md-menu> | ||
</md-menu-bar> | ||
</div> | ||
<div ng-repeat="entry in $ctrl.filteredData"> | ||
<div ng-if="$first || $ctrl.data[$index-1].compareDate != entry.compareDate" class="date"> | ||
{{ entry.date | date:'fullDate' }} | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try use the angular digest cycle more, e.g. having a function that gets called in the template
getEntries()
and that function returns filtered history data. Advantage: less explicit data management code.