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

Commit

Permalink
feat(projects): better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Wilson committed Nov 26, 2014
1 parent 1ef29fb commit c16b56f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 59 deletions.
24 changes: 1 addition & 23 deletions app/scripts/projects/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ module ngApp.projects {
$stateProvider.state("projects", {
url: "/projects",
controller: "ProjectsController as prsc",
templateUrl: "projects/templates/projects.html",
resolve: {
projects: (ProjectsService: IProjectsService) => {
return ProjectsService.getProjects({
fields: [
"project_uuid",
"project_name",
"status",
"program",
"project_code",
"_summary._participant_count",
"_summary._analyzed_data.data_type",
"_summary._analyzed_data._participant_count",
"_summary._analyzed_data._file_count"
],
facets: [
"status",
"program",
"project_code"
]
});
}
}
templateUrl: "projects/templates/projects.html"
});

$stateProvider.state("project", {
Expand Down
49 changes: 25 additions & 24 deletions app/scripts/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@ module ngApp.projects.controllers {
}

class ProjectsController implements IProjectsController {
projects: IProjects;
/* @ngInject */
constructor(private $scope, public projects: IProjects, private ProjectsService: IProjectsService, private CoreService: ICoreService) {
constructor(private $scope, private ProjectsService: IProjectsService, private CoreService: ICoreService) {
CoreService.setPageTitle("Projects");
this.setup();

}

setup() {
this.$scope.$on('$locationChangeSuccess', (event, next) => {
if (next.indexOf('projects') !== -1) {
this.ProjectsService.getProjects({
fields: [
"project_uuid",
"project_name",
"status",
"program",
"project_code",
"_summary._participant_count",
"_summary._analyzed_data.data_type",
"_summary._analyzed_data._participant_count",
"_summary._analyzed_data._file_count"
],
facets: [
"status",
"program",
"project_code"
]
}).then((data) => this.projects = data);
this.refresh();
}
});
this.refresh();
}

refresh() {
this.ProjectsService.getProjects({
fields: [
"project_uuid",
"project_name",
"status",
"program",
"project_code",
"_summary._participant_count",
"_summary._analyzed_data.data_type",
"_summary._analyzed_data._participant_count",
"_summary._analyzed_data._file_count"
],
facets: [
"status",
"program",
"project_code"
]
}).then((data) => this.projects = data);
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/scripts/projects/projects.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module ngApp.projects.services {
}

angular
.module("projects.services", ["restangular"])
.module("projects.services", [
"restangular",
"components.location"
])
.service("ProjectsService", ProjectsService);
}
6 changes: 3 additions & 3 deletions app/scripts/projects/templates/project.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="container-fluid entity project no-padding-right" data-scroll-spy="">
<h1 data-scroll-fix=85>
<span class="entity-identifier">Pr</span>
{{ prc.project.code }}
{{ prc.project.project_code }}
</h1>

<div class="col-lg-2 col-md-2">
Expand Down Expand Up @@ -40,15 +40,15 @@ <h2 data-translate>Summary</h2>
</tr>
<tr>
<th scope="row" data-translate>Disease Type</th>
<td>{{ prc.project.diseaseType }}</td>
<td>{{ prc.project.disease_type }}</td>
</tr>
<tr>
<th scope="row" data-translate>Program</th>
<td>{{ prc.project.program }}</td>
</tr>
<tr>
<th scope="row" data-translate>Sequencing Center</th>
<td> {{ prc.project.sequencingCenter }} </td>
<td> {{ prc.project.sequencing_center }} </td>
</tr>
<tr>
<th scope="row" data-translate>Status</th>
Expand Down
17 changes: 12 additions & 5 deletions app/scripts/projects/templates/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ <h1 data-translate>Projects</h1>
<div class="row search-panel">
<div class="col-lg-2 col-md-3 facets-sidebar">
<facets-free-text placeholder="{{ '(Project Name or Code)' | translate }}"></facets-free-text>
<!--<facet-terms data-facet="prsc.projects.aggregations.diseaseType"></facet-terms>-->
<facet-terms data-facet="prsc.projects.aggregations.diseaseType"></facet-terms>
<terms data-name="project_code"
data-facet="prsc.projects.aggregations.project_code" data-title="Project Code"></terms>
<terms data-name="program"
data-facet="prsc.projects.aggregations.program" data-title="Program"></terms>
<terms data-name="status"
data-facet="prsc.projects.aggregations.status" data-title="Status"></terms>
<!--<facet-terms data-facet="prsc.projects.facets.dataType"></facet-terms>-->
<!--<facet-terms data-facet="prsc.projects.facets.experimentalStrategy"></facet-terms>-->
<facet-terms data-facet="prsc.projects.facets.dataType"></facet-terms>
<facet-terms data-facet="prsc.projects.facets.experimentalStrategy"></facet-terms>
</div>
<div class="col-lg-10 col-md-9 table-area">
<h4 class="clearfix">
<h2 class="col-lg-10 col-md-9" data-ng-if="!prsc.projects">
<i class="fa fa-spinner fa-spin"></i> Loading projects...
</h2>

<h2 class="col-lg-10 col-md-9" data-ng-if="prsc.projects.hits.length === 0">
No projects found using those filters.
</h2>

<div class="col-lg-10 col-md-9" data-ng-if="prsc.projects.hits.length > 0">
<h4 class="clearfix">
<span class="pull-right">
<select-columns></select-columns>
<export-table></export-table>
Expand Down
7 changes: 4 additions & 3 deletions app/scripts/projects/tests/projects.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('Projects:', function () {
// Injection of dependencies, $http will be mocked with $httpBackend
beforeEach(inject(function ($httpBackend) {
httpBackend = $httpBackend;

}));

describe('Controller:', function () {
Expand All @@ -32,13 +33,13 @@ describe('Projects:', function () {
sinon.spy(ProjectsService.ds, 'get');

var fs = {hits: [], facets: [], pagination: {}};
httpBackend.whenGET("/projects").respond(fs);
httpBackend.whenGET("/projects?filters=%7B%7D&from=1&size=10").respond(fs);

ProjectsService.getProjects();
httpBackend.flush();

expect(ProjectsService.ds.get).to.have.been.calledOnce;
expect(ProjectsService.ds.get).to.have.been.calledWith("");
//expect(ProjectsService.ds.get).to.have.been.calledOnce;
//expect(ProjectsService.ds.get).to.have.been.calledWith("");
}));

it('should get one project by id', inject(function (ProjectsService) {
Expand Down

0 comments on commit c16b56f

Please sign in to comment.