WIP timeFrames

pull/6/head
Max Ehrlicher-Schmidt 4 years ago
parent c4214f20d4
commit 81100e51b6

@ -60,6 +60,7 @@
[editable]="data.isLockedByMe" [editable]="data.isLockedByMe"
[tableDataGQLType]="object.tableDataGQLType" [tableDataGQLType]="object.tableDataGQLType"
(referenceIds)="addReferenceIdsToObject($event, object)" (referenceIds)="addReferenceIdsToObject($event, object)"
[editableReferences]="object.editableReferences"
></app-reference-table> ></app-reference-table>
</mat-card> </mat-card>
</ng-container> </ng-container>

@ -7,24 +7,25 @@
overflow: auto; overflow: auto;
padding: 2em; padding: 2em;
.inline-card { .inline-card {
display: inline-table; display: inline-table;
min-width: 20em; min-width: 20em;
margin: 1em; margin: 1em;
} }
} }
#floating-fab-button-box { #floating-fab-button-box {
position: absolute; z-index: 999;
bottom: 2em; position: absolute;
right: 2em; bottom: 2em;
display: flex; right: 2em;
flex-direction: column; display: flex;
align-items: center; flex-direction: column;
.floating-fab-button { align-items: center;
margin-top: 0.5em; .floating-fab-button {
} margin-top: 0.5em;
}
.floating-fab-button-top {
position: absolute;
top: 2em;
right: 2em;
} }
}
.floating-fab-button-top {
position: absolute;
top: 2em;
right: 2em;
}

@ -1,6 +1,6 @@
<div class="table-page-wrapper"> <div class="table-page-wrapper">
<div class="table-control"> <div class="table-control">
<form [formGroup]="addForm"> <form [formGroup]="addForm" *ngIf="editableReferences">
<mat-form-field> <mat-form-field>
<input <input
type="text" type="text"
@ -14,7 +14,11 @@
<mat-option <mat-option
*ngFor="let element of possibleValueOptions" *ngFor="let element of possibleValueOptions"
[value]="nameToShowInSelection(element)" [value]="nameToShowInSelection(element)"
(click)="addReference(element); $event.stopPropagation(); trigger.openPanel()" (click)="
addReference(element);
$event.stopPropagation();
trigger.openPanel()
"
> >
{{ nameToShowInSelection(element) }} {{ nameToShowInSelection(element) }}
</mat-option> </mat-option>
@ -62,12 +66,21 @@
</th> </th>
<td mat-cell *matCellDef="let element"> <td mat-cell *matCellDef="let element">
<app-cell <app-cell
*ngIf="column.type === 'Boolean'; else stringValue" *ngIf="column.type === 'Boolean'"
[editable]="false" [editable]="false"
[(value)]="element[column.dataPath]" [(value)]="element[column.dataPath]"
[inputType]="column.type" [inputType]="column.type"
></app-cell> ></app-cell>
<ng-template #stringValue> <ng-container *ngIf="column.type === 'DateRange'">
<app-date-range-cell
[editable]="false"
[(from)]="element[column.dataPath + '.from']"
[(to)]="element[column.dataPath + '.to']"
></app-date-range-cell>
</ng-container>
<ng-container
*ngIf="column.type !== 'DateRange' && column.type !== 'NumRange'"
>
<span *ngIf="!column.link">{{ element[column.dataPath] }}</span> <span *ngIf="!column.link">{{ element[column.dataPath] }}</span>
<a <a
mat-button mat-button
@ -76,7 +89,7 @@
[routerLink]="column.link(element)" [routerLink]="column.link(element)"
>{{ element[column.dataPath] }}</a >{{ element[column.dataPath] }}</a
> >
</ng-template> </ng-container>
</td> </td>
</ng-container> </ng-container>

@ -47,9 +47,24 @@ export class ReferenceTableComponent {
} }
_editable: boolean = false; _editable: boolean = false;
@Input()
set editableReferences(value: boolean) {
if (value === false) {
this._editableReferences = false;
} else {
this._editableReferences = true;
}
}
get editableReferences(): boolean {
return this._editableReferences;
}
_editableReferences: boolean = true;
@Input() @Input()
set data(newdata) { set data(newdata) {
if (!newdata) { return; } if (!newdata) {
return;
}
this.dataSource.data = []; this.dataSource.data = [];
for (const element of newdata) { for (const element of newdata) {
this.dataSource.data.push(flatten(element)); this.dataSource.data.push(flatten(element));
@ -90,8 +105,9 @@ export class ReferenceTableComponent {
this.columnInfo.forEach((column) => { this.columnInfo.forEach((column) => {
this.displayedColumns.push(column.dataPath); this.displayedColumns.push(column.dataPath);
}); });
this.displayedColumns.push('buttons'); if (this.editableReferences) {
this.displayedColumns.push('buttons');
}
this.addForm this.addForm
.get('addGroup') .get('addGroup')
.valueChanges.subscribe(() => this.filterPossibleValueOptions()); .valueChanges.subscribe(() => this.filterPossibleValueOptions());
@ -111,17 +127,20 @@ export class ReferenceTableComponent {
} }
return item[columnName]; return item[columnName];
}; };
if (this.dataServiceThatProvidesThePossibleData) {
this.dataServiceThatProvidesThePossibleData.tableData.subscribe((data) => { this.dataServiceThatProvidesThePossibleData.tableData.subscribe(
this.possibleValues = []; (data) => {
if (data) { this.possibleValues = [];
for (const row of data) { if (data) {
this.possibleValues.push(flatten(row)); for (const row of data) {
this.possibleValues.push(flatten(row));
}
}
this.filterPossibleValueOptions();
} }
} );
this.filterPossibleValueOptions(); this.dataServiceThatProvidesThePossibleData.loadTableData();
}); }
this.dataServiceThatProvidesThePossibleData.loadTableData();
} }
addColumnPropertiesFromGQLSchemaToColumnInfo() { addColumnPropertiesFromGQLSchemaToColumnInfo() {
@ -145,7 +164,9 @@ export class ReferenceTableComponent {
const index = this.dataSource.data.findIndex( const index = this.dataSource.data.findIndex(
(element) => element.id === row.id (element) => element.id === row.id
); );
if (index === -1) { return; } if (index === -1) {
return;
}
this.dataSource.data.splice(index, 1); this.dataSource.data.splice(index, 1);
this.dataSource.data = this.dataSource.data; //needed to trigger update lol this.dataSource.data = this.dataSource.data; //needed to trigger update lol
this.filterPossibleValueOptions(); this.filterPossibleValueOptions();

@ -169,6 +169,20 @@
[(max)]="element[column.dataPath + '.max']" [(max)]="element[column.dataPath + '.max']"
></app-number-range-cell> ></app-number-range-cell>
</ng-container> </ng-container>
<ng-container *ngIf="column.type === 'DateRange'">
<app-date-range-cell
[editable]="
(element.newObject && column.acceptedForCreation) ||
(column.acceptedForUpdating && element.isLockedByMe)
"
[required]="
(element.newObject && column.required) ||
(element.isLockedByMe && column.required)
"
[(from)]="element[column.dataPath + '.from']"
[(to)]="element[column.dataPath + '.to']"
></app-date-range-cell>
</ng-container>
</td> </td>
</ng-container> </ng-container>

@ -211,6 +211,7 @@ export class TableComponent implements AfterViewInit {
? column.acceptedForCreation ? column.acceptedForCreation
: typeInformation.isPartOfType; : typeInformation.isPartOfType;
} }
console.log(this.columnInfo);
} }
getTranslation(dataPath: string) { getTranslation(dataPath: string) {

@ -30,31 +30,6 @@
</ng-template> </ng-template>
</div> </div>
<ng-container *ngIf="htmlInputType === 'dateRange'">
<mat-form-field>
<mat-label>Zeitraum auswählen</mat-label>
<mat-date-range-input [rangePicker]="picker" disabled>
<input
matStartDate
placeholder="Startdatum"
[value]="value?.from"
(dateChange)="startDateChange($event)"
/>
<input
matEndDate
placeholder="Enddatum"
[value]="value?.to"
(dateChange)="endDateChange($event)"
/>
</mat-date-range-input>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker
#picker
[disabled]="!editable"
></mat-date-range-picker>
</mat-form-field>
</ng-container>
<div <div
#otherInputType #otherInputType
*ngIf="htmlInputType === 'number' || htmlInputType === 'text'" *ngIf="htmlInputType === 'number' || htmlInputType === 'text'"

@ -120,27 +120,7 @@ export class CellComponent implements AfterViewInit {
this.valueChange.emit(this.value); this.valueChange.emit(this.value);
this.checkIfValid(); this.checkIfValid();
} }
startDateChange(event): void {
console.log('start');
console.log(event.value);
console.log(this.transformDate(event.value));
this.value.start = this.transformDate(event.value);
this.valueChange.emit(this.value);
}
endDateChange(event) {
console.log('end');
console.log(event.value);
console.log(this.transformDate(event.value));
this.value.end = this.transformDate(event.value);
this.valueChange.emit(this.value);
}
transformDate(date) {
return this.datepipe.transform(date, 'yyyy-MM-dd');
}
checkIfValid() { checkIfValid() {
setTimeout(() => { setTimeout(() => {
if (this.editable && this.required && this.inputType !== 'Boolean') { if (this.editable && this.required && this.inputType !== 'Boolean') {

@ -1 +1,25 @@
<p>date-range-cell works!</p> <mat-form-field *ngIf="editable || label; else stringValue">
<mat-label *ngIf="label">{{label}}</mat-label>
<mat-date-range-input [rangePicker]="picker" disabled class="date-range-input">
<input
matStartDate
placeholder="Startdatum"
[value]="from"
(dateChange)="startDateChange($event)"
/>
<input
matEndDate
placeholder="Enddatum"
[value]="to"
(dateChange)="endDateChange($event)"
/>
</mat-date-range-input>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker
#picker
[disabled]="!editable"
></mat-date-range-picker>
</mat-form-field>
<ng-template #stringValue>
<div class="date-string">{{toLocaleDate(from)}} <i>bis</i> {{toLocaleDate(to)}}</div>
</ng-template>

@ -0,0 +1,6 @@
.date-range-input {
min-width: 11em;
}
.date-string {
min-width: 10em;
}

@ -1,4 +1,13 @@
import { Component, OnInit } from '@angular/core'; import { DatePipe } from '@angular/common';
import {
Component,
Input,
Output,
EventEmitter,
ChangeDetectorRef,
OnInit,
} from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
@Component({ @Component({
selector: 'app-date-range-cell', selector: 'app-date-range-cell',
@ -6,10 +15,49 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./date-range-cell.component.scss'] styleUrls: ['./date-range-cell.component.scss']
}) })
export class DateRangeCellComponent implements OnInit { export class DateRangeCellComponent implements OnInit {
@Input()
from: string;
constructor() { } @Input()
to: string;
ngOnInit(): void { @Output() fromChange = new EventEmitter<string>();
@Output() toChange = new EventEmitter<string>();
@Input()
editable = false;
@Input()
required = false;
@Input()
label: string = null;
@Output() validityChange = new EventEmitter<boolean>();
isValid = true;
constructor(private cdr: ChangeDetectorRef, public datepipe: DatePipe) {}
ngOnInit() {
}
startDateChange(event): void {
this.from = this.transformDate(event.value);
this.fromChange.emit(this.from);
}
endDateChange(event) {
this.to = this.transformDate(event.value);
this.toChange.emit(this.to);
}
transformDate(date) {
return this.datepipe.transform(date, 'yyyy-MM-dd');
}
toLocaleDate(date: string): string {
if (date == "") {
return "";
}
return new Date(date).toLocaleDateString();
} }
} }

@ -219,6 +219,21 @@ export class BikeComponent implements OnInit {
}, },
propertyNameOfUpdateInput: 'equipmentIds', propertyNameOfUpdateInput: 'equipmentIds',
}, },
{
type: 'ReferenceTable',
title: 'Zeitscheiben',
dataPath: 'timeFrames',
dataService: null,
columnInfo: [
{ dataPath: 'dateRange', translation: 'Zeitraum' },
{ dataPath: 'lendingStation.name', translation: 'Standort' },
],
editableReferences: false,
linkToTable: (element) => '/table/timeFrames',
linkToTableParams: (bike) => {
return { filter: bike.name };
},
},
]; ];
headlineDataPath = 'name'; headlineDataPath = 'name';

@ -9,7 +9,7 @@ export class TimeFramesComponent implements OnInit {
headline = 'Zeitscheiben'; headline = 'Zeitscheiben';
columnInfo = [ columnInfo = [
{ dataPath: 'dataRange', translation: 'Zeitraum', type: 'DateRange', readonly: false }, { dataPath: 'dateRange', translation: 'Zeitraum', type: 'DateRange', readonly: false },
{ {
dataPath: 'cargoBike.name', dataPath: 'cargoBike.name',
translation: 'Lastenrad', translation: 'Lastenrad',
@ -19,7 +19,7 @@ export class TimeFramesComponent implements OnInit {
}, },
{ {
dataPath: 'lendingStation.name', dataPath: 'lendingStation.name',
translation: 'Ausleihstation', translation: 'Standort',
link: (element) => { link: (element) => {
return '/lendingStation/' + element['lendingStation.id']; return '/lendingStation/' + element['lendingStation.id'];
}, },

Loading…
Cancel
Save