diff --git a/front/current/assets/styles/components/_global.scss b/front/current/assets/styles/components/_global.scss index 91d80d85bae943d1e8b5ff888f55fadf3ceeb1d6..c6175ec9d0fbcd0047b25af93fbcceabd56353ab 100644 --- a/front/current/assets/styles/components/_global.scss +++ b/front/current/assets/styles/components/_global.scss @@ -38,9 +38,6 @@ p { ul, ol { margin: 0; padding: 0; - li { - line-height: $leading; - } ul, ol { margin-top: 0; margin-bottom: 0; diff --git a/front/current/assets/styles/components/_project-list.scss b/front/current/assets/styles/components/_project-list.scss index d686899d7a03697511dc4ca23c4b031fb7d47d1e..bdc2d8c32822fc729854280da0aa42847a28989f 100644 --- a/front/current/assets/styles/components/_project-list.scss +++ b/front/current/assets/styles/components/_project-list.scss @@ -21,6 +21,7 @@ table.projects { } td { text-align: left; + vertical-align: top; } } diff --git a/front/current/components/projects/list.component.html b/front/current/components/projects/list.component.html index ccafc8d90a5b6b5b634ec5d2b6cbab2247f9cdca..74f427e3e6e0c4574593a2f479d5995cae3fa637 100644 --- a/front/current/components/projects/list.component.html +++ b/front/current/components/projects/list.component.html @@ -38,6 +38,13 @@ +
  • + + +
  • diff --git a/front/current/components/projects/list.component.ts b/front/current/components/projects/list.component.ts index 589582041f8644011e3b1e5b3b7edd2cfedea0dc..bce9521b7a8c27831c5db2f9d939bf1f73095ebc 100644 --- a/front/current/components/projects/list.component.ts +++ b/front/current/components/projects/list.component.ts @@ -8,11 +8,14 @@ import { ProjectService } from '../../services/project/project.service'; import { DocumentSlotService } from '../../services/project/document-slot.service'; import { DocumentService } from '../../services/document/document.service'; +import { NewDocumentSlotComponent } from './new-document-slot.component'; + @Component({ selector: 'project-list', - templateUrl: config.static_url + '/components/projects/list.component.html' + templateUrl: config.static_url + '/components/projects/list.component.html', + directives: [NewDocumentSlotComponent] }) -export class ProjectListComponent implements OnInit{ +export class ProjectListComponent implements OnInit { constructor( private _router:Router, private _restService:RestService, @@ -26,8 +29,6 @@ export class ProjectListComponent implements OnInit{ public documentSlots:Collection; public documents:Collection; - errorMessage:string; - ngOnInit() { this.fetch(); }; diff --git a/front/current/components/projects/new-document-slot.component.html b/front/current/components/projects/new-document-slot.component.html new file mode 100644 index 0000000000000000000000000000000000000000..974682d65b65256ad34b93afe5f1e4e20311b0d2 --- /dev/null +++ b/front/current/components/projects/new-document-slot.component.html @@ -0,0 +1 @@ + diff --git a/front/current/components/projects/new-document-slot.component.ts b/front/current/components/projects/new-document-slot.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..8aa3ff0ce978e823e38f971249b3677065a5f53b --- /dev/null +++ b/front/current/components/projects/new-document-slot.component.ts @@ -0,0 +1,64 @@ +import { Component, OnInit } from 'angular2/core'; + +import { config } from '../../config'; +import { RestService, Model, Collection } from '../../services/rest.service'; + +import { DocumentSlotService } from '../../services/project/document-slot.service'; +import { DocumentService } from '../../services/document/document.service'; + +@Component({ + selector: 'new-document-slot', + inputs: ['project', 'documentSlots', 'documents'], + templateUrl: config.static_url + '/components/projects/new-document-slot.component.html' +}) +export class NewDocumentSlotComponent implements OnInit { + constructor( + private _restService:RestService, + + private _documentSlotService:DocumentSlotService, + private _documentService:DocumentService + ) {}; + + // Inputs + public project:Model; + public documentSlots:Collection; + public documents:Collection; + + public documentSlot:Model; + public document_:Model + + ngOnInit() { + this.documentSlot = this._restService.Model(this._documentSlotService, { + project_id: this.project.data['id'], + role: 'miscelaneous' + }); + this.document_ = this._restService.Model(this._documentService, {}); + }; + + public upload(e) { + let self = this; + + let el = e.currentTarget; + let file = el.files[0]; + let reader = new FileReader(); + + reader.addEventListener('load', () => { + self.document_ + .set({ + data: reader.result, + name: el.value.split(/(\\|\/)/g).pop() + }) + .save(() => { + self.documentSlot + .set({document_key: self.document_.data['key']}) + .save(() => { + self.documents.models.push(self.document_); + self.documentSlots.models.push(self.documentSlot); + self.ngOnInit(); + }); + }); + }, false); + if (file) + reader.readAsDataURL(file); + }; +}; diff --git a/front/current/lib/url.ts b/front/current/lib/url.ts new file mode 100644 index 0000000000000000000000000000000000000000..77bcc69196a11398197c454f41a57734161086f8 --- /dev/null +++ b/front/current/lib/url.ts @@ -0,0 +1,17 @@ +export function param(object) { + // Write an object to a url search string. + let url_components = []; + for (let key in object) { + let value = object[key]; + if (value instanceof Array) { + for (let i = 0; i < value.length; i++) { + url_components.push( + key + '[]' + '=' + encodeURIComponent(value[i]) + ) + } + } else { + url_components.push(key + '=' + encodeURIComponent(value)); + } + } + return '?' + url_components.join('&'); +} diff --git a/front/current/services/rest.service.ts b/front/current/services/rest.service.ts index 7ee6cf2916929573873dde98f0a3230c12a38b6c..68db1334998efe6f6e8db6001ad396f5903e5c06 100644 --- a/front/current/services/rest.service.ts +++ b/front/current/services/rest.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs/Observable'; import { config } from '../config'; import { extend } from '../lib/object'; +import { param } from '../lib/url'; export class Model { constructor( @@ -32,25 +33,11 @@ export class Model { }; get url(): string { - let params = new URLSearchParams(''); - - for (let key in this.filters) { - let value = this.filters[key]; - - if (typeof value[Symbol.iterator] === 'function') { - for (let i = 0; i < value.length; i++) { - params.set(key + '[]', value[i]); - } - } else { - params.set(key, value); - } - } - return ( this.service.config.url + this.service.url + (this.data['id'] || '') + - '?' + params.toString()); + param(this.filters)); }; parse(response:Response):Model { @@ -69,16 +56,20 @@ export class Model { .do(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; }) .subscribe(observer)); }; - save():Observable { + save(observer?):Observable { // Save a model to the server. - let method = (this.data['id'] ? 'put' : 'post'); + let self = this; + let method = (self.data['id'] ? 'put' : 'post'); + self.loading = true; + self.error = undefined; return ( - this._http[method]( - this.url, - JSON.stringify(this.data), + self._http[method]( + self.url, + JSON.stringify(self.data), {headers: config.HEADERS} ) - .map(this.parse)); + .do(self.parse.bind(self), self.setError.bind(self), () => { self.loading = false; }) + .subscribe(observer)); }; destroy():Observable { // Delete a model on the server. @@ -121,21 +112,7 @@ export class Collection { }; public get url(): string { - let params = new URLSearchParams(''); - - for (let key in this.filters) { - let value = this.filters[key]; - - if (typeof value[Symbol.iterator] === 'function') { - for (let i = 0; i < value.length; i++) { - params.set(key + '[]', value[i]); - } - } else { - params.set(key, value); - } - } - - return this.service.config.url + this.service.url + '?' + params.toString(); + return this.service.config.url + this.service.url + param(this.filters); }; parse(response:Response):Collection {