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

Commit

Permalink
fix(login): Filter terms for projects.
Browse files Browse the repository at this point in the history
- Filters terms on any project filter in UI to show
  only appropriate projects.
- Adds My Projects column to Search.Participants.
- Fixes errors from tableicious for compile step when
  missing data.

Closes #542
  • Loading branch information
Matthew Schranz committed Mar 13, 2015
1 parent 70037cc commit faf48e4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
15 changes: 13 additions & 2 deletions app/scripts/components/facets/facets.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module ngApp.components.facets.controllers {
inactives: string[] = [];

/* @ngInject */
constructor(private $scope: IFacetScope, private FacetService: IFacetService) {
constructor(private $scope: IFacetScope, private FacetService: IFacetService,
private UserService: IUserService) {
this.collapsed = !!$scope.collapsed;
this.expanded = !!$scope.expanded;
this.displayCount = this.originalDisplayCount = $scope.displayCount || 5;
Expand Down Expand Up @@ -58,6 +59,16 @@ module ngApp.components.facets.controllers {
}

refresh(terms) {
var projectCodeKeys = [
"project_id",
"participants.project.project_id",
"project.project_id"
];

if (projectCodeKeys.indexOf(this.name) !== -1) {
terms = this.UserService.setUserProjectsTerms(terms);
}

this.terms = terms;
this.actives = this.FacetService.getActives(this.name, terms);
this.inactives = _.difference(terms, this.actives);
Expand Down Expand Up @@ -199,7 +210,7 @@ module ngApp.components.facets.controllers {

}

angular.module("facets.controllers", ["facets.services"])
angular.module("facets.controllers", ["facets.services", "user.services"])
.controller("currentFiltersCtrl", CurrentFiltersController)
.controller("freeTextCtrl", FreeTextController)
.controller("termsCtrl", TermsController);
Expand Down
20 changes: 15 additions & 5 deletions app/scripts/components/tables/tableicious.cell.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ module ngApp.components.tables.directives.tableicious {
if ($scope.heading.compile) {
$element.empty();
$scope.row = $scope.$parent.datum;

var files = _.find($scope.row, (item) => {
return item.id === "files";
});

var htm;
try {
htm = $scope.heading.compile($scope);
} catch (e) {
htm = '<span>?</span>';
$log.error(e);
if (!files) {
htm = "<span>--</span>";
} else {
try {
htm = $scope.heading.compile($scope);
} catch (e) {
htm = '<span>?</span>';
$log.error(e);
}
}

var compiled = $compile(htm)($scope);
$element.append(compiled);
}
Expand Down
24 changes: 23 additions & 1 deletion app/scripts/components/user/user.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,33 @@ module ngApp.components.user.services {
}

isUserProject(file: IFile): boolean {
if (!this.currentUser) {
return false;
}

var projectIds = _.unique(_.map(file.participants, (participant) => {
return participant.project.project_id;
}));
return _.some(projectIds, (id) => {
return this.currentUser.projects.gdc_ids.indexOf(id);
return this.currentUser.projects.gdc_ids.indexOf(id) !== -1;
});
}

setUserProjectsTerms(terms) {
if (!this.currentUser || !this.currentUser.isFiltered) {
return terms;
}

return _.filter(terms, (term) => {
return this.isUserProject({
participants: [
{
project: {
project_id: term.key
}
}
]
});
});
}

Expand Down
21 changes: 20 additions & 1 deletion app/scripts/search/search.participants.table.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,26 @@ module ngApp.search.models {
return htm;

}
},{
}, {
displayName: "My Projects",
id: "my_projects",
enabled: function (scope) {
return scope.UserService.currentUser;
},
icon: function (field, row, scope) {
var project = _.find(row, function (elem) {
return elem.id === 'project'
}).val;
var UserService: IUserService = scope.UserService;
return UserService.isUserProject({
participants: [
{
project: project
}
]
}) ? 'check' : 'close';
}
}, {
displayName: "Participant ID",
id: "participant_id",
enabled: true,
Expand Down

0 comments on commit faf48e4

Please sign in to comment.