-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Allow to create and list contracts
- Loading branch information
Showing
29 changed files
with
1,559 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
assets/javascripts/controllers/form_new_contract_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This file is part of Bileto. | ||
// Copyright 2022-2023 Probesys | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
export default class extends Controller { | ||
static get targets () { | ||
return ['startAt', 'endAt']; | ||
} | ||
|
||
connect () { | ||
this.refreshMinEndAt(); | ||
} | ||
|
||
/** | ||
* Set the endAt input value to the end of the year of the startAt value. | ||
*/ | ||
updateEndAt () { | ||
const startAtDate = new Date(this.startAtTarget.value); | ||
const endAtDate = new Date(this.endAtTarget.value); | ||
|
||
if (isNaN(startAtDate)) { | ||
return; | ||
} | ||
|
||
if (isNaN(endAtDate) || startAtDate >= endAtDate) { | ||
// Add 1 day as it may set an invalid date if startAtDate is 31th | ||
// December. | ||
startAtDate.setDate(startAtDate.getDate() + 1); | ||
|
||
const startAtYear = startAtDate.getFullYear().toString(); | ||
this.endAtTarget.value = startAtYear + '-12-31'; | ||
} | ||
|
||
this.refreshMinEndAt(); | ||
} | ||
|
||
/** | ||
* Set the min value of endAt input to the startAt date + 1 day. | ||
*/ | ||
refreshMinEndAt () { | ||
const startAtDate = new Date(this.startAtTarget.value); | ||
|
||
if (isNaN(startAtDate)) { | ||
return; | ||
} | ||
|
||
startAtDate.setDate(startAtDate.getDate() + 1); | ||
|
||
const startAtYear = startAtDate.getFullYear().toString(); | ||
const startAtMonth = (startAtDate.getMonth() + 1).toString().padStart(2, '0'); | ||
const startAtDay = startAtDate.getDate().toString().padStart(2, '0'); | ||
this.endAtTarget.min = startAtYear + '-' + startAtMonth + '-' + startAtDay; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* This file is part of Bileto. */ | ||
/* Copyright 2022-2023 Probesys */ | ||
/* SPDX-License-Identifier: AGPL-3.0-or-later */ | ||
|
||
progress { | ||
display: block; | ||
width: 100%; | ||
height: 2rem; | ||
|
||
background-color: var(--color-primary2); | ||
border: 0.25rem solid var(--color-primary11); | ||
border-radius: 0.5rem; | ||
|
||
appearance: none; | ||
} | ||
|
||
progress::-webkit-progress-bar, | ||
progress::-moz-progress-bar { | ||
background-color: var(--color-primary9); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
// This file is part of Bileto. | ||
// Copyright 2022-2023 Probesys | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Platforms\MariaDBPlatform; | ||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20230914073949CreateContract extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create the contract table.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$dbPlatform = $this->connection->getDatabasePlatform(); | ||
if ($dbPlatform instanceof PostgreSQLPlatform) { | ||
$this->addSql('CREATE SEQUENCE contract_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
$this->addSql(<<<SQL | ||
CREATE TABLE contract ( | ||
id INT NOT NULL, | ||
created_by_id INT NOT NULL, | ||
updated_by_id INT NOT NULL, | ||
organization_id INT NOT NULL, | ||
uid VARCHAR(20) NOT NULL, | ||
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, | ||
updated_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
start_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, | ||
end_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, | ||
max_hours INT NOT NULL, | ||
notes TEXT NOT NULL, | ||
PRIMARY KEY(id) | ||
) | ||
SQL); | ||
$this->addSql('CREATE INDEX IDX_E98F2859B03A8386 ON contract (created_by_id)'); | ||
$this->addSql('CREATE INDEX IDX_E98F2859896DBBDE ON contract (updated_by_id)'); | ||
$this->addSql('CREATE INDEX IDX_E98F285932C8A3DE ON contract (organization_id)'); | ||
$this->addSql('COMMENT ON COLUMN contract.created_at IS \'(DC2Type:datetimetz_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN contract.updated_at IS \'(DC2Type:datetimetz_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN contract.start_at IS \'(DC2Type:datetimetz_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN contract.end_at IS \'(DC2Type:datetimetz_immutable)\''); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F2859B03A8386 | ||
FOREIGN KEY (created_by_id) | ||
REFERENCES "users" (id) | ||
NOT DEFERRABLE INITIALLY IMMEDIATE | ||
SQL); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F2859896DBBDE | ||
FOREIGN KEY (updated_by_id) | ||
REFERENCES "users" (id) | ||
NOT DEFERRABLE INITIALLY IMMEDIATE | ||
SQL); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F285932C8A3DE | ||
FOREIGN KEY (organization_id) | ||
REFERENCES organization (id) | ||
NOT DEFERRABLE INITIALLY IMMEDIATE | ||
SQL); | ||
} elseif ($dbPlatform instanceof MariaDBPlatform) { | ||
$this->addSql(<<<SQL | ||
CREATE TABLE contract ( | ||
id INT AUTO_INCREMENT NOT NULL, | ||
created_by_id INT NOT NULL, | ||
updated_by_id INT NOT NULL, | ||
organization_id INT NOT NULL, | ||
uid VARCHAR(20) NOT NULL, | ||
created_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)', | ||
updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)', | ||
name VARCHAR(255) NOT NULL, | ||
start_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)', | ||
end_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)', | ||
max_hours INT NOT NULL, | ||
notes LONGTEXT NOT NULL, | ||
INDEX IDX_E98F2859B03A8386 (created_by_id), | ||
INDEX IDX_E98F2859896DBBDE (updated_by_id), | ||
INDEX IDX_E98F285932C8A3DE (organization_id), | ||
PRIMARY KEY(id) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB | ||
SQL); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F2859B03A8386 | ||
FOREIGN KEY (created_by_id) | ||
REFERENCES `users` (id) | ||
SQL); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F2859896DBBDE | ||
FOREIGN KEY (updated_by_id) | ||
REFERENCES `users` (id) | ||
SQL); | ||
$this->addSql(<<<SQL | ||
ALTER TABLE contract | ||
ADD CONSTRAINT FK_E98F285932C8A3DE | ||
FOREIGN KEY (organization_id) | ||
REFERENCES organization (id) | ||
SQL); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$dbPlatform = $this->connection->getDatabasePlatform(); | ||
if ($dbPlatform instanceof PostgreSQLPlatform) { | ||
$this->addSql('DROP SEQUENCE contract_id_seq CASCADE'); | ||
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F2859B03A8386'); | ||
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F2859896DBBDE'); | ||
$this->addSql('ALTER TABLE contract DROP CONSTRAINT FK_E98F285932C8A3DE'); | ||
$this->addSql('DROP TABLE contract'); | ||
} elseif ($dbPlatform instanceof MariaDBPlatform) { | ||
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F2859B03A8386'); | ||
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F2859896DBBDE'); | ||
$this->addSql('ALTER TABLE contract DROP FOREIGN KEY FK_E98F285932C8A3DE'); | ||
$this->addSql('DROP TABLE contract'); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.