Login fix and rename columns in DB
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { User } from '../models/user.model';
|
||||
|
||||
@@ -12,7 +13,7 @@ export class AuthService {
|
||||
user!: User;
|
||||
|
||||
constructor(
|
||||
private http$: HttpClient
|
||||
private http$: HttpClient,
|
||||
) { }
|
||||
|
||||
ping() {
|
||||
@@ -33,20 +34,17 @@ export class AuthService {
|
||||
getAPIToken(credentials: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const header = new HttpHeaders().set('Content-type', 'application/json');
|
||||
this.http$.post<any>(`${environment.api.url}/auth/apiToken`, JSON.stringify(credentials), { headers: header }).subscribe({
|
||||
this.http$.post<any>(`${environment.api.url}/auth/apiToken`, JSON.stringify(credentials), { headers: header }).subscribe({
|
||||
next: (data) => {
|
||||
this.user.id = data.id;
|
||||
this.apiToken = data.token;
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => {
|
||||
console.error('apiToken error', e);
|
||||
error: (e: HttpErrorResponse) => {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
//const header = new HttpHeaders().set('Content-type', 'application/json');
|
||||
//return this.httpClient.post(this.path + "LoginWithGoogle", JSON.stringify(credentials), { headers: header });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
<div class="loading-container" *ngIf="loading">
|
||||
<img class="loading-img" src="../../assets/loader.gif" />
|
||||
</div>
|
||||
<div class="logo"></div>
|
||||
<div class="bg">
|
||||
<div class="container">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Component, NgZone, OnInit } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Router } from '@angular/router';
|
||||
import jwt_decode from "jwt-decode";
|
||||
import { AuthService } from 'src/app/auth/auth.service';
|
||||
@@ -14,34 +16,37 @@ import { environment } from 'src/environments/environment';
|
||||
|
||||
export class LoginPageComponent implements OnInit {
|
||||
constructor(
|
||||
private data$: DataService,
|
||||
private router$: Router,
|
||||
private auth$: AuthService,
|
||||
private ngZone$: NgZone
|
||||
) {}
|
||||
private ngZone$: NgZone,
|
||||
private snackBar$: MatSnackBar
|
||||
) { }
|
||||
|
||||
loading: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.snackBar$.open("", "", { duration: 1 });
|
||||
// @ts-ignore
|
||||
window.onGoogleLibraryLoad = () => {
|
||||
// @ts-ignore
|
||||
window.onGoogleLibraryLoad = () => {
|
||||
// @ts-ignore
|
||||
google.accounts.id.initialize({
|
||||
client_id: environment.google.clientId,
|
||||
callback: this.handleCredentialResponse.bind(this),
|
||||
auto_select: true,
|
||||
cancel_on_tap_outside: true
|
||||
});
|
||||
// @ts-ignore
|
||||
google.accounts.id.renderButton(
|
||||
google.accounts.id.initialize({
|
||||
client_id: environment.google.clientId,
|
||||
callback: this.handleCredentialResponse.bind(this),
|
||||
auto_select: true,
|
||||
cancel_on_tap_outside: true
|
||||
});
|
||||
// @ts-ignore
|
||||
google.accounts.id.renderButton(
|
||||
// @ts-ignore
|
||||
document.getElementById("google-button"),
|
||||
{ theme: "outline", size: "large", width: "100%" }
|
||||
);
|
||||
// @ts-ignore
|
||||
google.accounts.id.prompt((notification: PromptMomentNotification) => {});
|
||||
};
|
||||
{ theme: "outline", size: "large", width: "100%" }
|
||||
);
|
||||
// @ts-ignore
|
||||
google.accounts.id.prompt((notification: PromptMomentNotification) => { });
|
||||
};
|
||||
}
|
||||
|
||||
async handleCredentialResponse(response: any) {
|
||||
async handleCredentialResponse(response: any) {
|
||||
try {
|
||||
const responsePayload: any = jwt_decode(response.credential);
|
||||
this.auth$.user = new User({
|
||||
@@ -50,12 +55,20 @@ export class LoginPageComponent implements OnInit {
|
||||
email: responsePayload.email,
|
||||
avatar: responsePayload.picture
|
||||
});
|
||||
this.ngZone$.run(() => {
|
||||
this.loading = true;
|
||||
await this.auth$.getAPIToken(response.credential);
|
||||
this.ngZone$.run(() => {
|
||||
this.router$.navigate(['/app']);
|
||||
});
|
||||
await this.auth$.getAPIToken(response.credential);
|
||||
} catch (e) {
|
||||
console.error('Get user error', e);
|
||||
} catch (e: any) {
|
||||
this.loading = false;
|
||||
if (e.status === 401) {
|
||||
this.snackBar$.open("Użytkownik nie istnieje w bazie danych aplikacji Diuna.", "", { duration: 3000 });
|
||||
} else {
|
||||
this.snackBar$.open("Błąd połączenia z serwerem. Skontaktuj się z administratorem.", "", { duration: 3000 });
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ export class MainViewComponent {
|
||||
logout() {
|
||||
// @ts-ignore
|
||||
google.accounts.id.disableAutoSelect();
|
||||
this.router$.navigate(['']);
|
||||
this.auth$.user = new User({});
|
||||
this.reloadApp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DataService } from '../services/data.service';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
export class DataRow extends Base {
|
||||
mpk?: string;
|
||||
code?: string;
|
||||
value?: number;
|
||||
desc1?: string;
|
||||
desc2?: string;
|
||||
|
||||
@@ -2,12 +2,12 @@ import { Base } from './base.model';
|
||||
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { DataService } from '../services/data.service';
|
||||
import { map } from 'rxjs';
|
||||
import { DataRow } from './dataRow.model copy';
|
||||
|
||||
export class DataSet extends Base {
|
||||
number?: string;
|
||||
number?: Number;
|
||||
source?: string;
|
||||
name?: string;
|
||||
dataRows: DataRow[] = [];
|
||||
|
||||
@@ -22,8 +22,8 @@ export class DataSet extends Base {
|
||||
static getForm(fb: UntypedFormBuilder) {
|
||||
return fb.group({
|
||||
id: [null],
|
||||
number: ['', Validators.required],
|
||||
name: ['', Validators.required],
|
||||
source: ['', Validators.required],
|
||||
createdAt: '',
|
||||
modifiedAt: '',
|
||||
createdBy: '',
|
||||
@@ -84,6 +84,20 @@ export class DataSet extends Base {
|
||||
})
|
||||
});
|
||||
}
|
||||
static parseFile(file: any, _http: HttpClient): Promise<DataRow[]> {
|
||||
const formData = new FormData();
|
||||
formData.append(file.name, file);
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<DataRow[]>(`${environment.api.url}/datasets/parseFile`, formData,
|
||||
).pipe(map(data => data.map(x => new DataRow().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
/*
|
||||
static delete(id: string, _http: HttpClient): Promise<string> {
|
||||
return new Promise((resolve, reject)=> {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<form [formGroup]="form" (ngSubmit)="save()" novalidate>
|
||||
<mat-card appearance="outlined">
|
||||
<mat-toolbar color="secondary">
|
||||
Edycja zbioru danych
|
||||
Edycja warstwy danych
|
||||
<span class="fill-to-right"></span>
|
||||
<button mat-button type="submit" [disabled]="form.invalid">Zapisz</button>
|
||||
<button mat-button type="button" routerLink="../..">Anuluj</button>
|
||||
@@ -11,9 +11,9 @@
|
||||
<mat-grid-list cols="2" rowHeight="90px">
|
||||
<mat-grid-tile>
|
||||
<mat-form-field class="detail-input">
|
||||
<mat-label>Numer</mat-label>
|
||||
<input matInput formControlName="number">
|
||||
<mat-error *ngIf="form.controls['number'].touched && form.controls['number'].invalid">
|
||||
<mat-label>Nazwa</mat-label>
|
||||
<input matInput formControlName="name">
|
||||
<mat-error *ngIf="form.controls['name'].touched && form.controls['name'].invalid">
|
||||
Pole obowiązkowe
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
@@ -21,19 +21,48 @@
|
||||
|
||||
<mat-grid-tile>
|
||||
<mat-form-field class="detail-input">
|
||||
<mat-select placeholder="Źródło" formControlName="name" (selectionChange)="generateNumber()">
|
||||
<mat-option value="Import ręczny">Import ręczny</mat-option>
|
||||
<mat-option value="Arkusz Google">Arkusz Google</mat-option>
|
||||
<mat-select placeholder="Źródło" formControlName="source" (selectionChange)="generateNumber()">
|
||||
<mat-option value="CSV">CSV</mat-option>
|
||||
<mat-option value="GoogleSheet">GoogleSheet</mat-option>
|
||||
<mat-option value="SAP">SAP</mat-option>
|
||||
<mat-option value="Symfonia">Symfonia</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="form.controls['name'].touched && form.controls['name'].invalid">
|
||||
<mat-error *ngIf="form.controls['source'].touched && form.controls['source'].invalid">
|
||||
Pole obowiązkowe
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
</mat-grid-list>
|
||||
|
||||
<input type="file" class="file-input" (change)="onFileSelected($event)" #fileUpload>
|
||||
<button mat-mini-fab color="primary" type="button" class="upload-btn" (click)="fileUpload.click()">
|
||||
<mat-icon>attach_file</mat-icon>
|
||||
</button>
|
||||
|
||||
<mat-table #table [dataSource]="dataSource" [trackBy]="trackByUid" matSort class="animate">
|
||||
|
||||
<ng-container matColumnDef="code">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>MPK</mat-header-cell>
|
||||
<mat-cell *matCellDef="let item">{{item.code}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="desc1">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Konto</mat-header-cell>
|
||||
<mat-cell *matCellDef="let item">{{item.desc1}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="value">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Wartość</mat-header-cell>
|
||||
<mat-cell *matCellDef="let item">{{item.value | number:'1.2-2'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let item; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
<mat-paginator #paginator
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[5, 10, 20]">
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</form>
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
@import "../../../main-view/main-view.component.scss";
|
||||
@import "../../../main-view/main-view.component.scss";
|
||||
|
||||
.file-input {
|
||||
display: none;
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import moment from 'moment';
|
||||
import { AuthService } from 'src/app/auth/auth.service';
|
||||
import { DataRow } from 'src/app/models/dataRow.model copy';
|
||||
import { DataSet } from 'src/app/models/dataSet.model';
|
||||
import { DataService } from 'src/app/services/data.service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -19,6 +23,12 @@ export class DataSetEditComponent implements OnInit {
|
||||
public form!: UntypedFormGroup;
|
||||
private document!: DataSet;
|
||||
|
||||
displayedColumns = ['code', 'value', 'desc1'];
|
||||
dataSource!: MatTableDataSource<DataRow>;
|
||||
|
||||
@ViewChild(MatPaginator) paginator!: MatPaginator;
|
||||
@ViewChild(MatSort) sort!: MatSort;
|
||||
|
||||
constructor(
|
||||
private fb$: UntypedFormBuilder,
|
||||
private router$: Router,
|
||||
@@ -62,7 +72,17 @@ export class DataSetEditComponent implements OnInit {
|
||||
}
|
||||
generateNumber() {
|
||||
this.form.patchValue({
|
||||
number: `${this.form.controls['name'].value}-${moment().format("YYYY")}-${moment().format("MM")}`
|
||||
name: `${this.form.controls['source'].value}-${moment().format("YYYY")}${moment().format("MM")}${moment().format("DD")}${moment().format("HH")}${moment().format("mm")}`
|
||||
})
|
||||
}
|
||||
async onFileSelected(event : any) {
|
||||
const file = event.target.files[0];
|
||||
this.document.dataRows = await DataSet.parseFile(file, this.http$);
|
||||
this.dataSource = new MatTableDataSource(this.document.dataRows);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
}
|
||||
trackByUid(index : number, item : DataRow) {
|
||||
return item.id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user