diff --git a/.drone.yml b/.drone.yml index 11396c2..d44383a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,6 +1,6 @@ --- global-variables: - release: &release ${DRONE_BRANCH##**/} + release: &release ${DRONE_TAG} environment: &environment CRE_REGISTRY_IMAGE: registry.fyloz.dev:5443/colorrecipesexplorer/frontend CRE_PORT: 9102 @@ -21,6 +21,9 @@ steps: - echo -n "latest" > .tags when: branch: develop + event: + exclude: + - pull_request - name: set-docker-tags-release image: *alpine-image @@ -29,9 +32,10 @@ steps: commands: - echo -n "latest-release,$CRE_RELEASE" > .tags when: - branch: release/** + event: + - tag - - name: containerize + - name: containerize-dev image: plugins/docker environment: <<: *environment @@ -40,7 +44,16 @@ steps: when: branch: - develop - - release/** + + - name: containerize-release + image: plugins/docker + environment: + <<: *environment + settings: + repo: *docker-registry-repo + when: + event: + - tag - name: deploy image: alpine:latest @@ -70,10 +83,11 @@ steps: - ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker pull $CRE_REGISTRY_IMAGE:$CRE_RELEASE" - ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker run -d -p $CRE_PORT:80 --name=$DEPLOY_CONTAINER_NAME $CRE_REGISTRY_IMAGE:$CRE_RELEASE" when: - branch: release/** + event: + - tag trigger: branch: - develop - - release/** - - master + event: + - tag diff --git a/src/app/modules/accounts/accounts-routing.module.ts b/src/app/modules/accounts/accounts-routing.module.ts index 006c93f..5615140 100644 --- a/src/app/modules/accounts/accounts-routing.module.ts +++ b/src/app/modules/accounts/accounts-routing.module.ts @@ -1,14 +1,13 @@ import {NgModule} from '@angular/core' import {RouterModule, Routes} from '@angular/router' -import {LogoutComponent} from './pages/logout/logout.component' -import {Login} from './accounts' +import {Login, Logout} from './accounts' const routes: Routes = [{ path: 'login', component: Login }, { path: 'logout', - component: LogoutComponent + component: Logout }, { path: '', redirectTo: 'login' diff --git a/src/app/modules/accounts/accounts.module.ts b/src/app/modules/accounts/accounts.module.ts index c8a05ec..353042f 100644 --- a/src/app/modules/accounts/accounts.module.ts +++ b/src/app/modules/accounts/accounts.module.ts @@ -1,19 +1,16 @@ import {NgModule} from '@angular/core' import {AccountsRoutingModule} from './accounts-routing.module' -import {LoginComponent} from './pages/login/login.component' import {SharedModule} from '../shared/shared.module' -import {LogoutComponent} from './pages/logout/logout.component' -import {Login} from './accounts' +import {Login, Logout} from './accounts' import {CreInputsModule} from '../shared/components/inputs/inputs.module' import {CreButtonsModule} from '../shared/components/buttons/buttons.module' @NgModule({ declarations: [ - LoginComponent, - LogoutComponent, - Login + Login, + Logout ], imports: [ SharedModule, diff --git a/src/app/modules/accounts/accounts.ts b/src/app/modules/accounts/accounts.ts index 10f850b..81b477f 100644 --- a/src/app/modules/accounts/accounts.ts +++ b/src/app/modules/accounts/accounts.ts @@ -1,12 +1,11 @@ import {Component, HostListener, ViewChild} from '@angular/core' import {FormControl, Validators} from '@angular/forms' -import {ErrorHandlingComponent} from '../shared/components/subscribing.component' +import {ErrorHandlingComponent, SubscribingComponent} from '../shared/components/subscribing.component' import {AccountService} from './services/account.service' import {AppState} from '../shared/app-state' import {ErrorHandler, ErrorService} from '../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' import {CreForm, ICreForm} from "../shared/components/forms/forms"; -import {take, takeUntil} from "rxjs/operators"; import {AlertService} from "../shared/service/alert.service"; @Component({ @@ -61,3 +60,32 @@ export class Login extends ErrorHandlingComponent { } } } + +@Component({ + selector: 'cre-logout', + template: '' +}) +export class Logout extends SubscribingComponent { + constructor( + private accountService: AccountService, + private alertService: AlertService, + private appState: AppState, + errorService: ErrorService, + router: Router, + activatedRoute: ActivatedRoute + ) { + super(errorService, activatedRoute, router) + this.appState.title = 'Connexion' + } + + ngOnInit(): void { + if (!this.appState.isAuthenticated) { + this.urlUtils.navigateTo('/account/login') + } + + this.subscribeAndNavigate( + this.accountService.logout(), + '/account/login' + ) + } +} diff --git a/src/app/modules/accounts/pages/login/login.component.html b/src/app/modules/accounts/pages/login/login.component.html deleted file mode 100644 index 28aa77c..0000000 --- a/src/app/modules/accounts/pages/login/login.component.html +++ /dev/null @@ -1,36 +0,0 @@ -
- - - Connexion au système - - - - Numéro d'utilisateur - - person - - Un numéro d'utilisateur est requis - Le numéro d'utilisateur doit être un nombre - - - - Mot de passe - - lock - - Un mot de passe est requis - - - - - - - -
diff --git a/src/app/modules/accounts/pages/login/login.component.sass b/src/app/modules/accounts/pages/login/login.component.sass deleted file mode 100644 index afd1937..0000000 --- a/src/app/modules/accounts/pages/login/login.component.sass +++ /dev/null @@ -1,8 +0,0 @@ -mat-card - width: 25rem - - .alert p - margin: 0 - - mat-form-field - width: 100% diff --git a/src/app/modules/accounts/pages/login/login.component.ts b/src/app/modules/accounts/pages/login/login.component.ts deleted file mode 100644 index 919bed0..0000000 --- a/src/app/modules/accounts/pages/login/login.component.ts +++ /dev/null @@ -1,55 +0,0 @@ -import {Component, OnInit} from '@angular/core' -import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms' -import {AccountService} from '../../services/account.service' -import {ActivatedRoute, Router} from '@angular/router' -import {ErrorService} from '../../../shared/service/error.service' -import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' -import {AppState} from '../../../shared/app-state' - -@Component({ - selector: 'cre-login', - templateUrl: './login.component.html', - styleUrls: ['./login.component.sass'] -}) -export class LoginComponent extends ErrorHandlingComponent implements OnInit { - form: FormGroup - idFormControl: FormControl - passwordFormControl: FormControl - - constructor( - private formBuilder: FormBuilder, - private accountService: AccountService, - private appState: AppState, - errorService: ErrorService, - router: Router, - activatedRoute: ActivatedRoute - ) { - super(errorService, activatedRoute, router) - this.appState.title = 'Connexion' - } - - ngOnInit(): void { - this.errorService.activeErrorHandler = this - - if (this.appState.isAuthenticated) { - this.router.navigate(['/color']) - } - - this.idFormControl = this.formBuilder.control(null, Validators.compose([Validators.required, Validators.pattern(new RegExp('^[0-9]+$'))])) - this.passwordFormControl = this.formBuilder.control(null, Validators.required) - this.form = this.formBuilder.group({ - id: this.idFormControl, - password: this.passwordFormControl - }) - } - - submit() { - this.subscribe( - this.accountService.login( - this.idFormControl.value, - this.passwordFormControl.value - ), - response => console.log(response) - ) - } -} diff --git a/src/app/modules/accounts/pages/logout/logout.component.html b/src/app/modules/accounts/pages/logout/logout.component.html deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/modules/accounts/pages/logout/logout.component.sass b/src/app/modules/accounts/pages/logout/logout.component.sass deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/modules/accounts/pages/logout/logout.component.ts b/src/app/modules/accounts/pages/logout/logout.component.ts deleted file mode 100644 index a1433c1..0000000 --- a/src/app/modules/accounts/pages/logout/logout.component.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {Component} from '@angular/core'; -import {AccountService} from "../../services/account.service"; -import {ActivatedRoute, Router} from "@angular/router"; -import {AppState} from "../../../shared/app-state"; -import {SubscribingComponent} from "../../../shared/components/subscribing.component"; -import {ErrorService} from "../../../shared/service/error.service"; - -@Component({ - selector: 'cre-logout', - templateUrl: './logout.component.html', - styleUrls: ['./logout.component.sass'] -}) -export class LogoutComponent extends SubscribingComponent { - - constructor( - private accountService: AccountService, - private appState: AppState, - errorService: ErrorService, - router: Router, - activatedRoute: ActivatedRoute - ) { - super(errorService, activatedRoute, router) - } - - ngOnInit(): void { - if (!this.appState.isAuthenticated) { - this.urlUtils.navigateTo('/account/login') - } - - this.subscribeAndNavigate( - this.accountService.logout(), - '/account/login' - ) - } -} diff --git a/src/app/modules/recipes/mix/mix.ts b/src/app/modules/recipes/mix/mix.ts index a91833f..7257668 100644 --- a/src/app/modules/recipes/mix/mix.ts +++ b/src/app/modules/recipes/mix/mix.ts @@ -27,7 +27,7 @@ abstract class _BaseMixPage extends SubscribingComponent { protected mixService: MixService, private recipeService: RecipeService, private materialTypeService: MaterialTypeService, - private materialService: MaterialService, + protected materialService: MaterialService, errorService: ErrorService, router: Router, activatedRoute: ActivatedRoute @@ -50,13 +50,15 @@ abstract class _BaseMixPage extends SubscribingComponent { set recipe(recipe: Recipe) { this._recipe = recipe - this.materials$ = this.materialService.getAllForMixCreation(recipe.id) + this.materials$ = this.fetchMaterials(recipe.id) } get recipe(): Recipe { return this._recipe } + protected abstract fetchMaterials(recipeId: number): Observable + abstract submit(dto: MixSaveDto) } @@ -65,6 +67,10 @@ abstract class _BaseMixPage extends SubscribingComponent { templateUrl: 'add.html' }) export class MixAdd extends _BaseMixPage { + protected fetchMaterials(recipeId: number): Observable { + return this.materialService.getAllForMixCreation(recipeId) + } + submit(dto: MixSaveDto) { this.subscribeAndNavigate( this.mixService.saveDto(dto), @@ -80,21 +86,27 @@ export class MixAdd extends _BaseMixPage { export class MixEdit extends _BaseMixPage { mix: Mix + private mixId: number + ngOnInit() { super.ngOnInit() + this.mixId = this.urlUtils.parseIntUrlParam('id') + this.fetchMix() } private fetchMix() { - const mixId = this.urlUtils.parseIntUrlParam('id') - this.subscribe( - this.mixService.getById(mixId), + this.mixService.getById(this.mixId), mix => this.mix = mix ) } + protected fetchMaterials(recipeId: number): Observable { + return this.materialService.getAllForMixUpdate(this.mixId) + } + submit(dto: MixSaveDto) { this.subscribeAndNavigate( this.mixService.updateDto({...dto, id: this.mix.id}),