From 918ad9486168ee9607c295ddec9e052fd8b3389a Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 14:13:18 +0100 Subject: [PATCH 1/7] Correcting preview link --- front/app/src/app/views/contracts/drafts.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/app/src/app/views/contracts/drafts.component.ts b/front/app/src/app/views/contracts/drafts.component.ts index afae7314..0907bd81 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 From 8aac5376dfcdde1f60347d317e1b42bd03dc21da Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 14:13:59 +0100 Subject: [PATCH 2/7] Adding translation for Cratract draft creation form --- back/app/contract/schemas.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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): From b1d0e115f4685641542e0106fecefdb1507ed55c Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 14:36:02 +0100 Subject: [PATCH 3/7] Dynamic asset url depending on request host --- back/app/contract/print/__init__.py | 26 ++++++++++---------- back/app/contract/print/templates/print.html | 2 +- back/app/contract/print/templates/styles.css | 10 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) 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..aa8a61e7 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 }}

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; } From b4f81431b915a657d0d6d53cad370eebb0bd2ed6 Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 14:56:14 +0100 Subject: [PATCH 4/7] Making entity birthday optionalble --- back/app/entity/models.py | 3 +- front/app/src/common/crud/types/date.type.ts | 54 +++++++++------- .../src/common/crud/types/datetime.type.ts | 63 ++++++++++++------- 3 files changed, 73 insertions(+), 47 deletions(-) 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/common/crud/types/date.type.ts b/front/app/src/common/crud/types/date.type.ts index c998b9e9..53b0b363 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,13 @@ 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() { @@ -54,8 +52,13 @@ export class DateTypeComponent extends FieldType implements OnI } 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 +71,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..a5b6a1ae 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,13 @@ 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() { @@ -58,9 +57,15 @@ export class DatetimeTypeComponent extends FieldType implements } 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 +86,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('') + } } } From 4be6591e81f5c254ff1c2e66871e327a15302eed Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 15:55:18 +0100 Subject: [PATCH 5/7] Hidding birthplace when empty on contract --- back/app/contract/print/templates/print.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/app/contract/print/templates/print.html b/back/app/contract/print/templates/print.html index aa8a61e7..a0340bf0 100644 --- a/back/app/contract/print/templates/print.html +++ b/back/app/contract/print/templates/print.html @@ -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" %} From 86bcb874275878aa2993b15e86e6c40d0f60d9d7 Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 15:59:01 +0100 Subject: [PATCH 6/7] Updating date input type to allow empty dates --- front/app/src/common/crud/types/date.type.ts | 5 ++++- front/app/src/common/crud/types/datetime.type.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/front/app/src/common/crud/types/date.type.ts b/front/app/src/common/crud/types/date.type.ts index 53b0b363..2cce32ef 100644 --- a/front/app/src/common/crud/types/date.type.ts +++ b/front/app/src/common/crud/types/date.type.ts @@ -17,7 +17,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
@@ -29,6 +28,7 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; (ngModelChange)="changeDatetime($event)" ngbDatepicker #d="ngbDatepicker" + [class.is-invalid]="showError" />
@@ -49,6 +49,9 @@ export class DateTypeComponent extends FieldType implements OnI 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 => { diff --git a/front/app/src/common/crud/types/datetime.type.ts b/front/app/src/common/crud/types/datetime.type.ts index a5b6a1ae..5b64907b 100644 --- a/front/app/src/common/crud/types/datetime.type.ts +++ b/front/app/src/common/crud/types/datetime.type.ts @@ -14,7 +14,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
@@ -26,6 +25,7 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; (ngModelChange)="changeDatetime($event)" ngbDatepicker #d="ngbDatepicker" + [class.is-invalid]="showError" /> 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 => { From 08cb2772eaee71da9f00a848e4e7adce834864d7 Mon Sep 17 00:00:00 2001 From: ewandor Date: Tue, 14 Mar 2023 15:59:23 +0100 Subject: [PATCH 7/7] Updating default value of contract create form --- front/app/src/app/views/contracts/drafts.component.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/front/app/src/app/views/contracts/drafts.component.ts b/front/app/src/app/views/contracts/drafts.component.ts index 0907bd81..6786f56f 100644 --- a/front/app/src/app/views/contracts/drafts.component.ts +++ b/front/app/src/app/views/contracts/drafts.component.ts @@ -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",