add perms; editor, viewer

This commit is contained in:
pakintada@gmail.com 2023-12-18 08:49:23 +07:00
parent b647517ca6
commit 1ac38f26cb
8 changed files with 74 additions and 21 deletions

View file

@ -9,11 +9,13 @@ import {
} from '@angular/forms';
import { forEach, isEqual, sortBy } from 'lodash';
import { first } from 'rxjs';
import { UserPermissions } from 'src/app/core/auth/userPermissions';
import {
RecipeDetail,
RecipeDetailMat,
} from 'src/app/core/models/recipe.model';
import { RecipeService } from 'src/app/core/services/recipe.service';
import { UserService } from 'src/app/core/services/user.service';
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
@Component({
@ -30,7 +32,8 @@ export class RecipeListComponent implements OnInit {
constructor(
private _recipeService: RecipeService,
private _formBuilder: FormBuilder
private _formBuilder: FormBuilder,
private _userService: UserService
) {}
recipeListForm = this._formBuilder.group(
@ -51,17 +54,17 @@ export class RecipeListComponent implements OnInit {
result.forEach((recipeDetailMat: RecipeDetailMat) => {
this.recipeListData.push(
this._formBuilder.group({
isUse: recipeDetailMat.isUse,
materialPathId: recipeDetailMat.materialPathId,
isUse: [{ value: recipeDetailMat.isUse, disabled: !this.isEditable()}],
materialPathId: [{value:recipeDetailMat.materialPathId, disabled: !this.isEditable()}],
name: [{ value: recipeDetailMat.name, disabled: true }],
mixOrder: recipeDetailMat.mixOrder,
stirTime: recipeDetailMat.stirTime,
powderGram: recipeDetailMat.powderGram,
powderTime: recipeDetailMat.powderTime,
syrupGram: recipeDetailMat.syrupGram,
syrupTime: recipeDetailMat.syrupTime,
waterCold: recipeDetailMat.waterCold,
waterYield: recipeDetailMat.waterYield,
mixOrder: [{ value:recipeDetailMat.mixOrder, disabled: !this.isEditable()}],
stirTime: [{value:recipeDetailMat.stirTime, disabled: !this.isEditable()}],
powderGram: [{value:recipeDetailMat.powderGram, disabled: !this.isEditable()}],
powderTime: [{value:recipeDetailMat.powderTime, disabled: !this.isEditable()}],
syrupGram: [{value:recipeDetailMat.syrupGram, disabled: !this.isEditable()}],
syrupTime: [{value: recipeDetailMat.syrupTime, disabled: !this.isEditable()}],
waterCold: [{value:recipeDetailMat.waterCold, disabled: !this.isEditable()}],
waterYield: [{value:recipeDetailMat.waterYield, disabled: !this.isEditable()}],
})
);
});
@ -99,4 +102,8 @@ export class RecipeListComponent implements OnInit {
get recipeListData(): FormArray {
return this.recipeListForm.get('recipeListData') as FormArray;
}
isEditable(){
return this._userService.getCurrentUser()!.permissions.includes(UserPermissions.EDITOR);
}
}