From 59e68421d2f57ba136397183409b8b5f8e6c4780 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 16:23:14 -0400 Subject: [PATCH 01/10] Move controllers > components. --- .../current/{controllers => components}/app/app.component.html | 0 front/current/{controllers => components}/app/app.component.ts | 2 +- .../current/{controllers => components}/nav/nav.component.html | 0 front/current/{controllers => components}/nav/nav.component.ts | 2 +- .../{controllers => components}/projects/list.component.html | 0 .../{controllers => components}/projects/list.component.ts | 2 +- front/current/main.ts | 2 +- 7 files changed, 4 insertions(+), 4 deletions(-) rename front/current/{controllers => components}/app/app.component.html (100%) rename front/current/{controllers => components}/app/app.component.ts (91%) rename front/current/{controllers => components}/nav/nav.component.html (100%) rename front/current/{controllers => components}/nav/nav.component.ts (78%) rename front/current/{controllers => components}/projects/list.component.html (100%) rename front/current/{controllers => components}/projects/list.component.ts (90%) diff --git a/front/current/controllers/app/app.component.html b/front/current/components/app/app.component.html similarity index 100% rename from front/current/controllers/app/app.component.html rename to front/current/components/app/app.component.html diff --git a/front/current/controllers/app/app.component.ts b/front/current/components/app/app.component.ts similarity index 91% rename from front/current/controllers/app/app.component.ts rename to front/current/components/app/app.component.ts index 2e8070c..1775bd3 100644 --- a/front/current/controllers/app/app.component.ts +++ b/front/current/components/app/app.component.ts @@ -13,7 +13,7 @@ import { ProjectListComponent } from '../projects/list.component'; @Component({ selector: 'my-app', - templateUrl: config.static_url + '/controllers/app/app.component.html', + templateUrl: config.static_url + '/components/app/app.component.html', providers: [ ROUTER_PROVIDERS, RestService, ProjectService diff --git a/front/current/controllers/nav/nav.component.html b/front/current/components/nav/nav.component.html similarity index 100% rename from front/current/controllers/nav/nav.component.html rename to front/current/components/nav/nav.component.html diff --git a/front/current/controllers/nav/nav.component.ts b/front/current/components/nav/nav.component.ts similarity index 78% rename from front/current/controllers/nav/nav.component.ts rename to front/current/components/nav/nav.component.ts index 2946a83..8e57ad5 100644 --- a/front/current/controllers/nav/nav.component.ts +++ b/front/current/components/nav/nav.component.ts @@ -5,7 +5,7 @@ import { config } from '../../config'; @Component({ selector: 'navigation-bar', - templateUrl: config.static_url + '/controllers/nav/nav.component.html', + templateUrl: config.static_url + '/components/nav/nav.component.html', directives: [ROUTER_DIRECTIVES] }) export class NavComponent { diff --git a/front/current/controllers/projects/list.component.html b/front/current/components/projects/list.component.html similarity index 100% rename from front/current/controllers/projects/list.component.html rename to front/current/components/projects/list.component.html diff --git a/front/current/controllers/projects/list.component.ts b/front/current/components/projects/list.component.ts similarity index 90% rename from front/current/controllers/projects/list.component.ts rename to front/current/components/projects/list.component.ts index 212d184..c765ca6 100644 --- a/front/current/controllers/projects/list.component.ts +++ b/front/current/components/projects/list.component.ts @@ -7,7 +7,7 @@ import { ProjectService } from '../../services/project/project.service'; @Component({ selector: 'project-list', - templateUrl: config.static_url + '/controllers/projects/list.component.html' + templateUrl: config.static_url + '/components/projects/list.component.html' }) export class ProjectListComponent implements OnInit{ constructor( diff --git a/front/current/main.ts b/front/current/main.ts index 0404bf4..ddb323b 100644 --- a/front/current/main.ts +++ b/front/current/main.ts @@ -1,6 +1,6 @@ import { bootstrap } from 'angular2/platform/browser'; import { HTTP_PROVIDERS } from 'angular2/http'; -import { AppComponent } from './controllers/app/app.component'; +import { AppComponent } from './components/app/app.component'; import 'rxjs/Rx'; -- GitLab From da9be63e3ebf19c9436c5c9fac3ee65ce2d52aeb Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 16:38:46 -0400 Subject: [PATCH 02/10] Remove unused import from project service. --- front/current/services/project/project.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/front/current/services/project/project.service.ts b/front/current/services/project/project.service.ts index 1c69e6e..d41e5b7 100644 --- a/front/current/services/project/project.service.ts +++ b/front/current/services/project/project.service.ts @@ -1,7 +1,5 @@ import { Injectable } from 'angular2/core'; - import { config } from '../../config'; -import { RestService } from '../rest.service'; @Injectable() export class ProjectService { -- GitLab From aec8451ec93c73ea5ce767a861213fd2f5270ece Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 17:02:23 -0400 Subject: [PATCH 03/10] Add a document service. --- front/current/services/document/document.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 front/current/services/document/document.service.ts diff --git a/front/current/services/document/document.service.ts b/front/current/services/document/document.service.ts new file mode 100644 index 0000000..3850b18 --- /dev/null +++ b/front/current/services/document/document.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from 'angular2/core'; +import { config } from '../../config'; + +@Injectable() +export class DocumentService { + public config:any = config.SERVICES.document; + public url:string = '/document/'; +}; -- GitLab From c0d40d197cf43f713f9d0e3b76011d689597d284 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 17:02:33 -0400 Subject: [PATCH 04/10] Add a project service. --- front/current/services/project/document-slot.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 front/current/services/project/document-slot.service.ts diff --git a/front/current/services/project/document-slot.service.ts b/front/current/services/project/document-slot.service.ts new file mode 100644 index 0000000..8f0960f --- /dev/null +++ b/front/current/services/project/document-slot.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from 'angular2/core'; +import { config } from '../../config'; + +@Injectable() +export class DocumentSlotService { + public config:any = config.SERVICES.project; + public url:string = '/project/document/'; +}; -- GitLab From 0de3518e69ad61c8c12c311f8bd61b4a988880f5 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 17:02:54 -0400 Subject: [PATCH 05/10] Add support for a callback in the model and collection fetch methods. --- front/current/services/rest.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/front/current/services/rest.service.ts b/front/current/services/rest.service.ts index aa18f4c..7a40d84 100644 --- a/front/current/services/rest.service.ts +++ b/front/current/services/rest.service.ts @@ -50,12 +50,13 @@ export class Model { this.error = response.json(); }; - fetch() { + fetch(observer?) { // Update a model from the server. let self = this; self.loading = true; self.error = undefined; return (self._http.get(self.url, {headers: config.HEADERS}) + .do(observer) .subscribe(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; })); }; save():Observable { @@ -124,12 +125,13 @@ export class Collection { this.error = response.json(); }; - fetch() { + fetch(observer?) { // Get a list of models from the server. let self = this; self.loading = true; self.error = undefined; return (self._http.get(self.url, {headers: config.HEADERS}) + .do(observer) .subscribe(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; })); }; }; -- GitLab From a752502c6013511cf2264b42635eddc61c948164 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 17:03:30 -0400 Subject: [PATCH 06/10] Include the document and project services as providers. --- front/current/components/app/app.component.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/front/current/components/app/app.component.ts b/front/current/components/app/app.component.ts index 1775bd3..d93420f 100644 --- a/front/current/components/app/app.component.ts +++ b/front/current/components/app/app.component.ts @@ -9,6 +9,8 @@ import { ProjectService } from '../../services/project/project.service'; import { NavComponent } from '../nav/nav.component'; import { ProjectListComponent } from '../projects/list.component'; +import { DocumentSlotService } from '../../services/project/document-slot.service'; +import { DocumentService } from '../../services/document/document.service'; @Component({ @@ -16,7 +18,9 @@ import { ProjectListComponent } from '../projects/list.component'; templateUrl: config.static_url + '/components/app/app.component.html', providers: [ ROUTER_PROVIDERS, - RestService, ProjectService + RestService, + ProjectService, DocumentSlotService, + DocumentService ], directives: [ROUTER_DIRECTIVES, NavComponent] }) -- GitLab From eb1cf050a4f527039a4eb62ac0831d2d9b3cf776 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 18:02:31 -0400 Subject: [PATCH 07/10] Call callbacks in the model/collection fetch methods after calling parse(). --- front/current/services/rest.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/front/current/services/rest.service.ts b/front/current/services/rest.service.ts index 7a40d84..452da54 100644 --- a/front/current/services/rest.service.ts +++ b/front/current/services/rest.service.ts @@ -56,8 +56,8 @@ export class Model { self.loading = true; self.error = undefined; return (self._http.get(self.url, {headers: config.HEADERS}) - .do(observer) - .subscribe(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; })); + .do(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; }) + .subscribe(observer)); }; save():Observable { // Save a model to the server. @@ -131,8 +131,8 @@ export class Collection { self.loading = true; self.error = undefined; return (self._http.get(self.url, {headers: config.HEADERS}) - .do(observer) - .subscribe(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; })); + .do(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; }) + .subscribe(observer)); }; }; -- GitLab From 8e3cb1197fe535c1f9357dbd4b565bf8b6bd02eb Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 18:02:42 -0400 Subject: [PATCH 08/10] Remove list padding. --- front/current/assets/styles/components/_global.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/current/assets/styles/components/_global.scss b/front/current/assets/styles/components/_global.scss index 3a545ef..91d80d8 100644 --- a/front/current/assets/styles/components/_global.scss +++ b/front/current/assets/styles/components/_global.scss @@ -36,7 +36,7 @@ p { margin-bottom: 0; } ul, ol { - margin: $leading, 0, $leading, 0; + margin: 0; padding: 0; li { line-height: $leading; -- GitLab From d16ba13566d24ef6293740a72acd956b3645dd24 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 18:03:07 -0400 Subject: [PATCH 09/10] Remove list styling for the document list in the project list. --- front/current/assets/styles/components/_project-list.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/front/current/assets/styles/components/_project-list.scss b/front/current/assets/styles/components/_project-list.scss index b0318b6..d686899 100644 --- a/front/current/assets/styles/components/_project-list.scss +++ b/front/current/assets/styles/components/_project-list.scss @@ -29,4 +29,10 @@ table.projects { border-bottom: none; } } + + ul.document-list { + li { + list-style: none; + } + } } -- GitLab From a619f1167acac6c80aab83aff866d7b46969f7b4 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Tue, 12 Apr 2016 18:03:16 -0400 Subject: [PATCH 10/10] Add document list. --- .../components/projects/list.component.html | 20 +++++- .../components/projects/list.component.ts | 68 +++++++++++++++++-- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/front/current/components/projects/list.component.html b/front/current/components/projects/list.component.html index e4688ae..187e942 100644 --- a/front/current/components/projects/list.component.html +++ b/front/current/components/projects/list.component.html @@ -3,16 +3,17 @@ status name + documents - + - + {{ projects.error['status'] }}: {{ projects.error['short'] }} @@ -21,6 +22,21 @@ {{ project.data['state'] }} {{ project.data['name'] }} + + + diff --git a/front/current/components/projects/list.component.ts b/front/current/components/projects/list.component.ts index c765ca6..35cf76c 100644 --- a/front/current/components/projects/list.component.ts +++ b/front/current/components/projects/list.component.ts @@ -3,7 +3,10 @@ import { Router } from 'angular2/router'; import { config } from '../../config'; import { RestService, Model, Collection } from '../../services/rest.service'; + import { ProjectService } from '../../services/project/project.service'; +import { DocumentSlotService } from '../../services/project/document-slot.service'; +import { DocumentService } from '../../services/document/document.service'; @Component({ selector: 'project-list', @@ -13,20 +16,73 @@ export class ProjectListComponent implements OnInit{ constructor( private _router:Router, private _restService:RestService, - private _projectService:ProjectService + + private _projectService:ProjectService, + private _documentSlotService:DocumentSlotService, + private _documentService:DocumentService ) {}; public projects:Collection; - public selectedProject:Model; + public documentSlots:Collection; + public documents:Collection; errorMessage:string; ngOnInit() { this.fetch(); - } + }; + + public getDocumentSlotsForProject(project:Model):Collection { + let documentSlots = []; + let collection = this._restService.Collection(this._documentSlotService, []); + + for (let documentSlot of this.documentSlots.models) { + if (documentSlot.data['project_id'] == project.data['id']) + documentSlots.push(documentSlot); + } + + collection.models = documentSlots; + return collection; + }; + + public getDocumentForDocumentSlot(documentSlot:Model):Model { + for (let document_ of this.documents.models) { + if (document_.data['key'] == documentSlot.data['document_key']) { + return document_; + } + } + }; fetch() { - (this.projects = this._restService.Collection(this._projectService, [])) - .fetch(); + let self = this; + + self.projects = self._restService.Collection(self._projectService, []); + self.documentSlots = self._restService.Collection(self._documentSlotService, []); + self.documents = self._restService.Collection(self._documentService, []); + + self.projects.fetch(() => { + let keys = []; + + for (let project of self.projects.models) { + let key = project.data['key']; + if (keys.indexOf(key) == -1) + keys.push(key) + } + + self.documentSlots + .setFilters({project_ids: keys}) + .fetch(() => { + let keys = []; + + for (let document_slot of self.documentSlots.models) { + let key = document_slot['document_key']; + keys.push(key); + } + + self.documents + .setFilters({keys: keys}) + .fetch(); + }); + }); }; -} +}; -- GitLab