diff --git a/back/app/contract/print/__init__.py b/back/app/contract/print/__init__.py index d356da39..ee7e4798 100644 --- a/back/app/contract/print/__init__.py +++ b/back/app/contract/print/__init__.py @@ -2,7 +2,7 @@ import datetime import os import base64 -from fastapi import APIRouter, HTTPException +from fastapi import APIRouter, HTTPException, Request from fastapi.responses import HTMLResponse, FileResponse from fastapi.templating import Jinja2Templates @@ -61,47 +61,47 @@ print_router = APIRouter() templates = Jinja2Templates(directory=str(BASE_PATH / "templates")) -async def render_print(host, contract): +async def render_print(root_url, contract): template = templates.get_template("print.html") return template.render({ "contract": contract, - "static_host": host + "root_url": root_url }) -async def render_css(host, contract): +async def render_css(root_url, contract): template = templates.get_template("styles.css") return template.render({ "contract": contract, - "static_host": host + "root_url": root_url }) @print_router.get("/preview/draft/{draft_id}", response_class=HTMLResponse) -async def preview_draft(draft_id: str) -> str: +async def preview_draft(draft_id: str, request: Request) -> str: draft = await build_model(await ContractDraft.get(draft_id)) - return await render_print('localhost', draft) + return await render_print(f'{request.url.scheme}://{request.url.hostname}', draft) @print_router.get("/preview/signature/{signature_id}", response_class=HTMLResponse) -async def preview_contract_by_signature(signature_id: str) -> str: +async def preview_contract_by_signature(signature_id: str, request: Request) -> str: contract = await Contract.find_by_signature_id(signature_id) for p in contract.parties: if p.signature_affixed: p.signature_png = retrieve_signature_png(f'media/signatures/{p.signature_uuid}.png') - return await render_print('localhost', contract) + return await render_print(f'{request.url.scheme}://{request.url.hostname}', contract) @print_router.get("/preview/{contract_id}", response_class=HTMLResponse) -async def preview_contract(contract_id: str) -> str: +async def preview_contract(contract_id: str, request: Request) -> str: contract = await Contract.get(contract_id) for p in contract.parties: if p.signature_affixed: p.signature_png = retrieve_signature_png(f'media/signatures/{p.signature_uuid}.png') - return await render_print('localhost', contract) + return await render_print(f'{request.url.scheme}://{request.url.hostname}', contract) @print_router.get("/pdf/{contract_id}", response_class=FileResponse) @@ -118,8 +118,8 @@ async def create_pdf(contract_id: str) -> str: # os.remove(signature_path) font_config = FontConfiguration() - html = HTML(string=await render_print('nginx', contract)) - css = CSS(string=await render_css('nginx', contract), font_config=font_config) + html = HTML(string=await render_print('http://nginx', contract)) + css = CSS(string=await render_css('http://nginx', contract), font_config=font_config) html.write_pdf(contract_path, stylesheets=[css], font_config=font_config) update_query = {"$set": { diff --git a/back/app/contract/print/templates/print.html b/back/app/contract/print/templates/print.html index 0e7440fc..a0340bf0 100644 --- a/back/app/contract/print/templates/print.html +++ b/back/app/contract/print/templates/print.html @@ -8,7 +8,7 @@
- +
Cooper, Hillman & Toshi LLP
6834 Innocence Boulevard
LOS SANTOS - SA
consulting@cht.law.com

{{ contract.title|upper }}

@@ -27,7 +27,7 @@ {{ party.entity.entity_data.title }} société de {{ party.entity.entity_data.activity }} enregistrée auprès du gouvernement de San Andreas et domiciliée au {{ party.entity.address }}{% if party.representative %}, représentée par {{ party.representative.entity_data.firstname }} {{ party.representative.entity_data.middlenames }} {{ party.representative.entity_data.lastname }}{% endif %} {% elif party.entity.entity_data.type == "individual" %} {{ party.entity.entity_data.firstname }} {{ party.entity.entity_data.middlenames }} {{ party.entity.entity_data.lastname }} - {% if party.entity.entity_data.day_of_birth %} né le {{ party.entity.entity_data.day_of_birth.strftime('%d/%m/%Y') }} {% if true %} à {{ party.entity.entity_data.place_of_birth }}{% endif %},{% endif %} + {% if party.entity.entity_data.day_of_birth %} né le {{ party.entity.entity_data.day_of_birth.strftime('%d/%m/%Y') }} {% if party.entity.entity_data.place_of_birth %} à {{ party.entity.entity_data.place_of_birth }}{% endif %},{% endif %} {% if party.entity.address %} résidant à {{ party.entity.address }}, {% endif %} {% elif party.entity.entity_data.type == "institution" %} diff --git a/back/app/contract/print/templates/styles.css b/back/app/contract/print/templates/styles.css index 2807d7d4..768011e1 100644 --- a/back/app/contract/print/templates/styles.css +++ b/back/app/contract/print/templates/styles.css @@ -1,24 +1,24 @@ @font-face { font-family: 'Century Schoolbook'; - src: url('http://{{ static_host }}/assets/century-schoolbook/CenturySchoolbookRegular.ttf'); + src: url('{{ root_url }}/assets/century-schoolbook/CenturySchoolbookRegular.ttf'); } @font-face { font-family: "Century Schoolbook"; - src: url("http://{{ static_host }}/assets/century-schoolbook/CenturySchoolbookBold.ttf"); + src: url("{{ root_url }}/assets/century-schoolbook/CenturySchoolbookBold.ttf"); font-weight: bold; } @font-face { font-family: "Century Schoolbook"; - src: url("http://{{ static_host }}/assets/century-schoolbook/CenturySchoolbookItalic.ttf"); + src: url("{{ root_url }}/assets/century-schoolbook/CenturySchoolbookItalic.ttf"); font-style: italic; } @font-face { font-family: "Century Schoolbook"; - src: url("http://{{ static_host }}/assets/century-schoolbook/CenturySchoolbookBoldItalic.ttf"); + src: url("{{ root_url }}/assets/century-schoolbook/CenturySchoolbookBoldItalic.ttf"); font-weight: bold; font-style: italic; } @@ -31,7 +31,7 @@ content: "© Cooper, Hillman & Toshi LLC - {{ contract.name }} - Page " counter(page) "/" counter(pages); font-size: 0.8em; } - background: url('http://{{ static_host }}/assets/watermark.png') no-repeat; + background: url('{{ root_url }}/assets/watermark.png') no-repeat; background-size:contain; } diff --git a/back/app/contract/schemas.py b/back/app/contract/schemas.py index dffa9ac3..e70bfdaa 100644 --- a/back/app/contract/schemas.py +++ b/back/app/contract/schemas.py @@ -15,13 +15,17 @@ class ContractDraftRead(ContractDraft): class ContractDraftCreate(Writer): - name: str - title: str - parties: List[DraftParty] - provisions: List[DraftProvision] + name: str = Field(title='Nom') + title: str = Field(title='Titre') + parties: List[DraftParty] = Field(title='Parties') + provisions: List[DraftProvision] = Field( + props={"items-per-row": "1", "numbered": True}, + title='Clauses' + ) variables: List[DictionaryEntry] = Field( default=[], format="dictionary", + title='Variables' ) async def validate_foreign_key(self): diff --git a/back/app/entity/models.py b/back/app/entity/models.py index 5ee30e35..450129b6 100644 --- a/back/app/entity/models.py +++ b/back/app/entity/models.py @@ -23,10 +23,9 @@ class Individual(EntityType): props={"items-per-row": "4", "numbered": True}, title="Surnoms" ) - day_of_birth: date = Field(title='Date de naissance') + day_of_birth: date = Field(default=None, title='Date de naissance') place_of_birth: str = Field(default="", title='Lieu de naissance') - @property def label(self) -> str: if len(self.surnames) > 0: diff --git a/front/app/src/app/views/contracts/drafts.component.ts b/front/app/src/app/views/contracts/drafts.component.ts index afae7314..6786f56f 100644 --- a/front/app/src/app/views/contracts/drafts.component.ts +++ b/front/app/src/app/views/contracts/drafts.component.ts @@ -97,7 +97,7 @@ export class DraftsNewComponent extends BaseDraftsComponent implements OnInit { (resourceReceived)="this.onResourceReceived($event)" > - Preview + Preview @@ -105,18 +105,20 @@ export class DraftsNewComponent extends BaseDraftsComponent implements OnInit { ` }) export class DraftsCardComponent extends BaseDraftsComponent implements OnInit { - resource_id: string | null = null;templateModel: {} = {}; + resource_id: string | null = null; + templateModel: {} = {}; isReadyForPublication = false; newContractFormfields: FormlyFieldConfig[] = []; newContractForm: FormGroup = new FormGroup({}); newContractModel: any = { - date: formatDate(new Date(),'YYYY-MM-dd', 'EN_US', 'CET'), + date: new Date(), location: "Los Santos, SA", draft_id: null } fieldJson = { type: "object", + required: ["date", "location", "draft_id"], properties: { date: { type: "string", diff --git a/front/app/src/common/crud/types/date.type.ts b/front/app/src/common/crud/types/date.type.ts index c998b9e9..2cce32ef 100644 --- a/front/app/src/common/crud/types/date.type.ts +++ b/front/app/src/common/crud/types/date.type.ts @@ -1,7 +1,6 @@ - -import { Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { formatDate } from "@angular/common"; -import { NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; +import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; @@ -15,12 +14,12 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; +
- + -
- +
`, }) export class DateTypeComponent extends FieldType implements OnInit { - public date : NgbDateStruct; - public datetime : Date = new Date(); + public date : NgbDateStruct | null = null; + public datetime : Date | null = null; constructor() { super(); - this.date = this.getDateStruct(new Date()); } ngOnInit() { if (this.formControl.value === undefined) { this.changeDatetime({}); + } else { + this.datetime = new Date(this.formControl.value); + this.date = this.getDateStruct(this.datetime); } this.formControl.valueChanges.subscribe(value => { - this.datetime = new Date(value) - this.date = this.getDateStruct(this.datetime); + if (value) { + this.datetime = new Date(value); + this.date = this.getDateStruct(this.datetime); + } else { + this.datetime = null; + this.date = null; + } }) } @@ -68,12 +74,21 @@ export class DateTypeComponent extends FieldType implements OnI } changeDatetime(event: any) { - this.datetime.setFullYear(this.date.year) - this.datetime.setMonth(this.date.month - 1) - this.datetime.setDate(this.date.day) + if (this.date) { + if (!this.datetime) { + this.datetime = new Date(); + } + this.datetime.setFullYear(this.date.year) + this.datetime.setMonth(this.date.month - 1) + this.datetime.setDate(this.date.day) - this.formControl.setValue( - formatDate(this.datetime, 'YYYY-MM-dd', 'EN_US', 'CET') - ) + this.formControl.setValue( + formatDate(this.datetime, 'YYYY-MM-dd', 'EN_US', 'CET') + ) + } else { + this.datetime = null; + this.date = null; + this.formControl.setValue('') + } } } diff --git a/front/app/src/common/crud/types/datetime.type.ts b/front/app/src/common/crud/types/datetime.type.ts index a7997c46..5b64907b 100644 --- a/front/app/src/common/crud/types/datetime.type.ts +++ b/front/app/src/common/crud/types/datetime.type.ts @@ -1,5 +1,4 @@ - -import { Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { formatDate } from "@angular/common"; import { NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; @@ -12,12 +11,12 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; class="form-label">{{ props.label }} +
- + -
- +
`, }) export class DatetimeTypeComponent extends FieldType implements OnInit { - public time : NgbTimeStruct; - public date : NgbDateStruct; - public datetime : Date = new Date() + public time : NgbTimeStruct | null = null; + public date : NgbDateStruct | null = null; + public datetime : Date | null = null; constructor() { @@ -55,12 +54,21 @@ export class DatetimeTypeComponent extends FieldType implements ngOnInit() { if (this.formControl.value === undefined) { this.changeDatetime({}); + } else { + this.datetime = new Date(this.formControl.value); + this.date = this.getDateStruct(this.datetime); } this.formControl.valueChanges.subscribe(value => { - this.datetime = new Date(value) - this.date = this.getDateStruct(this.datetime); - this.time = this.getTimeStruct(this.datetime); + if (value) { + this.datetime = new Date(value); + this.date = this.getDateStruct(this.datetime); + this.time = this.getTimeStruct(this.datetime); + } else { + this.datetime = null; + this.date = null; + this.time = null; + } }) } @@ -81,15 +89,25 @@ export class DatetimeTypeComponent extends FieldType implements } changeDatetime(event: any) { - this.datetime.setFullYear(this.date.year) - this.datetime.setMonth(this.date.month - 1) - this.datetime.setDate(this.date.day) - this.datetime.setHours(this.time.hour) - this.datetime.setMinutes(this.time.minute) - this.datetime.setSeconds(this.time.second) + if (this.date && this.time) { + if (!this.datetime) { + this.datetime = new Date(); + } + this.datetime.setFullYear(this.date.year) + this.datetime.setMonth(this.date.month - 1) + this.datetime.setDate(this.date.day) + this.datetime.setHours(this.time.hour) + this.datetime.setMinutes(this.time.minute) + this.datetime.setSeconds(this.time.second) - this.formControl.setValue( - formatDate(this.datetime, 'YYYY-MM-ddTHH:mm:ss.SSS', 'EN_US', 'CET') - ) + this.formControl.setValue( + formatDate(this.datetime, 'YYYY-MM-ddTHH:mm:ss.SSS', 'EN_US', 'CET') + ) + } else { + this.datetime = null; + this.date = null; + this.time = null; + this.formControl.setValue('') + } } }