Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

History filtering #382 #449

Merged
merged 10 commits into from May 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 104 additions & 1 deletion client/app/components/group/_history/history.controller.js
@@ -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(){
Copy link
Member

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.

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(){
Copy link
Member

Choose a reason for hiding this comment

The 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) => {
Expand Down
45 changes: 44 additions & 1 deletion client/app/components/group/_history/history.html
@@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to use the translate directive over filters to reduce the watches.
<span translate="HISTORY.TYPES.GROUPS"></span>

<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>
Expand Down
6 changes: 5 additions & 1 deletion client/app/components/group/_history/history.js
Expand Up @@ -2,10 +2,14 @@ import angular from "angular";
import uiRouter from "angular-ui-router";
import historyComponent from "./history.component";
import profilePicture from "../../_profilePicture/profilePicture";
import StoreModule from "../../../services/store/store";
import UserModule from "../../../services/user/user";

let historyModule = angular.module("history", [
uiRouter,
profilePicture
profilePicture,
StoreModule,
UserModule
])

.component("history", historyComponent)
Expand Down
12 changes: 11 additions & 1 deletion client/app/locales/locale-en.json
Expand Up @@ -184,7 +184,17 @@
"SERIES_DELETE": "deleted a recurring pick-up",
"PICKUP_DONE": "did a pick-up at {{store_name}}",
"PICKUP_JOIN": "signed up to do a pick-up at {{store_name}}",
"PICKUP_LEAVE": "stepped back from doing a pick-up at {{store_name}}"
"PICKUP_LEAVE": "stepped back from doing a pick-up at {{store_name}}",
"STORES": "Stores",
"USERS": "Users",
"TYPE": "Type",
"SELECT_ALL": "Select all",
"SELECT_NONE": "Select none",
"TYPES": {
"GROUPS": "Group related",
"STORES": "Store related",
"PICKUPS": "Pick-up related"
}
},
"NOTIFICATIONS": {
"TITLE": "Notifications",
Expand Down