Skip to content

Instantly share code, notes, and snippets.

@aj-dev
Created December 8, 2016 19:00
Show Gist options
  • Save aj-dev/7b44f90aff55bb11bfcc670448832f5c to your computer and use it in GitHub Desktop.
Save aj-dev/7b44f90aff55bb11bfcc670448832f5c to your computer and use it in GitHub Desktop.
CardsController
(function () {
'use strict';
angular.module('evbox.cards')
.controller('CardsController', CardsController);
CardsController.$inject = ['cardService', 'permissionService', 'utils'];
function CardsController(cardService, permissionService, utils) {
var $ctrl = this;
$ctrl.$onInit = function () {
$ctrl.viewModes = ['list', 'grid'];
$ctrl.greeting = utils.getDayPeriod();
$ctrl.state = {
viewMode: $ctrl.viewModes[0],
canRegisterCard: permissionService.resolve($ctrl.profile.permissions, ['CARD:CREATE'])
};
$ctrl.titles = cardService.getOrderTitles();
$ctrl.columns = cardService.getColumns(['holder', 'reference', 'contractId'], 'cards.list.columns.', {property: 'holder'});
$ctrl.sortingSelectOptions = cardService.getSortOptions($ctrl.columns.slice(), {property: 'holder'});
$ctrl.sortingSelectActive = _.find($ctrl.sortingSelectOptions, {isActive: true, isDesc: false});
};
/**
* Sets the viewMode for the report
* @param {string} viewMode
*/
$ctrl.setMode = function (viewMode) {
$ctrl.state.viewMode = viewMode ? viewMode : $ctrl.viewModes[0];
};
/**
* Orders cards by a given column in list view
* @param {Object} column
*/
$ctrl.orderBy = function (column) {
cardService.updateOptionState($ctrl.sortingSelectOptions, column);
$ctrl.sortingSelectActive = _.find($ctrl.sortingSelectOptions, {isActive: true, isDesc: !column.isDesc});
cardService.updateColumnState($ctrl.columns, {property: column.property, isDesc: column.isDesc});
$ctrl.cards = cardService.orderBy($ctrl.cards, column.property, column.isDesc);
};
/**
* Orders cards using drop-down select options in grid view
* @param {Object} option
*/
$ctrl.selectOrderBy = function (option) {
var selectedOption = _.assign({}, option);
cardService.updateColumnState($ctrl.columns, {property: selectedOption.property, isDesc: !selectedOption.isDesc});
$ctrl.cards = cardService.orderBy($ctrl.cards, selectedOption.property, selectedOption.isDesc);
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment