Skip to content

Instantly share code, notes, and snippets.

@scarney81
Last active August 29, 2015 14:07
Show Gist options
  • Save scarney81/76ceb19cbe18d4f13f56 to your computer and use it in GitHub Desktop.
Save scarney81/76ceb19cbe18d4f13f56 to your computer and use it in GitHub Desktop.
binding function from pre
//= require ../index
(function () {
'use strict';
angular
.module('projects/directives')
.directive('projects', function ($q, currentUser, Project, Workflow, viewOptions) {
return {
restrict: 'E',
require: 'projects',
templateUrl: '/projects/directives/projects/projects.html',
compile: function () {
return {
pre: function (scope, element, attrs, controller) {
$q
.all([
currentUser.$promise.then(function () {
scope.currentUser = currentUser;
}),
Workflow.query().$promise.then(function (workflows) {
scope.workflows = workflows;
})
])
.then(function () {
scope.options.workflow = scope.options.workflow || scope.workflows[0];
});
controller.refresh();
}
};
},
controller: function ($scope) {
this.refresh = function (filter) {
filter = filter || viewOptions.get('projects', 'filter');
var options = {
limit: 1000,
offset: 0,
query: filter
};
Project
.search(options)
.$promise
.then(function (projects) {
$scope.projects = projects;
$scope.grouped = _.groupBy($scope.projects, function (project) {
return project.workflow.id;
});
});
};
}
};
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment