#14 Add message in the color list
This commit is contained in:
parent
ae5dac1040
commit
951f9fcb87
|
@ -5,7 +5,7 @@
|
||||||
matInput
|
matInput
|
||||||
type="text"
|
type="text"
|
||||||
[(ngModel)]="searchQuery"
|
[(ngModel)]="searchQuery"
|
||||||
(keyup)="searchRecipes()"/>
|
(keyup)="searchRecipes()"/>
|
||||||
<button
|
<button
|
||||||
mat-button
|
mat-button
|
||||||
*ngIf="searchQuery"
|
*ngIf="searchQuery"
|
||||||
|
@ -20,18 +20,23 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="recipes.size === 0" class="alert alert-warning w-50 m-auto text-center">
|
||||||
|
<p>Il n'y a actuellement aucune recette enregistrée dans le système.</p>
|
||||||
|
<p *ngIf="hasEditPermission">Vous pouvez en créer une <b><a routerLink="/color/add">ici</a></b>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<mat-expansion-panel
|
<mat-expansion-panel
|
||||||
class="table-title"
|
class="table-title"
|
||||||
*ngFor="let companyRecipes of recipes"
|
*ngFor="let company of companies"
|
||||||
[hidden]="isCompanyHidden(companyRecipes.recipes)"
|
[hidden]="isCompanyHidden(company)"
|
||||||
[expanded]="panelForcedExpanded">
|
[expanded]="panelForcedExpanded">
|
||||||
<mat-expansion-panel-header>
|
<mat-expansion-panel-header>
|
||||||
<mat-panel-title>
|
<mat-panel-title>
|
||||||
{{companyRecipes.company}}
|
{{company.name}}
|
||||||
</mat-panel-title>
|
</mat-panel-title>
|
||||||
</mat-expansion-panel-header>
|
</mat-expansion-panel-header>
|
||||||
|
|
||||||
<ng-container *ngTemplateOutlet="recipeTableTemplate; context: {recipes: companyRecipes.recipes}"></ng-container>
|
<ng-container *ngTemplateOutlet="recipeTableTemplate; context: {recipes: recipes.get(company.id)}"></ng-container>
|
||||||
</mat-expansion-panel>
|
</mat-expansion-panel>
|
||||||
|
|
||||||
<ng-template
|
<ng-template
|
||||||
|
|
|
@ -8,7 +8,9 @@ import {ActivatedRoute, Router} from '@angular/router'
|
||||||
import {ErrorService} from '../../../shared/service/error.service'
|
import {ErrorService} from '../../../shared/service/error.service'
|
||||||
import {AppState} from '../../../shared/app-state'
|
import {AppState} from '../../../shared/app-state'
|
||||||
import {ConfigService} from '../../../shared/service/config.service'
|
import {ConfigService} from '../../../shared/service/config.service'
|
||||||
import {Config} from '../../../shared/model/config.model'
|
import {Company} from '../../../shared/model/company.model';
|
||||||
|
import {CompanyService} from '../../../company/service/company.service';
|
||||||
|
import {Config} from '../../../shared/model/config.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'cre-list',
|
selector: 'cre-list',
|
||||||
|
@ -16,13 +18,15 @@ import {Config} from '../../../shared/model/config.model'
|
||||||
styleUrls: ['./list.component.sass']
|
styleUrls: ['./list.component.sass']
|
||||||
})
|
})
|
||||||
export class ListComponent extends ErrorHandlingComponent {
|
export class ListComponent extends ErrorHandlingComponent {
|
||||||
recipes: { company: string, recipes: Recipe[] }[] = []
|
companies: Company[] = []
|
||||||
|
recipes: Map<number, Recipe[]> = new Map<number, Recipe[]>()
|
||||||
tableCols = ['name', 'description', 'color', 'sample', 'iconNotApproved', 'buttonView', 'buttonEdit']
|
tableCols = ['name', 'description', 'color', 'sample', 'iconNotApproved', 'buttonView', 'buttonEdit']
|
||||||
searchQuery = ''
|
searchQuery = ''
|
||||||
panelForcedExpanded = false
|
panelForcedExpanded = false
|
||||||
hiddenRecipes = []
|
hiddenRecipes = []
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private companyService: CompanyService,
|
||||||
private recipeService: RecipeService,
|
private recipeService: RecipeService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
|
@ -37,21 +41,35 @@ export class ListComponent extends ErrorHandlingComponent {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
super.ngOnInit()
|
super.ngOnInit()
|
||||||
this.appState.title = "Explorateur"
|
this.appState.title = 'Explorateur'
|
||||||
|
|
||||||
|
// Navigate to configs if server is in emergency mode
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
this.configService.get(Config.EMERGENCY_MODE),
|
this.configService.get(Config.EMERGENCY_MODE),
|
||||||
config => {
|
config => {
|
||||||
if (config.content === "false") {
|
if (config.content == "true") {
|
||||||
this.subscribe(
|
this.urlUtils.navigateTo('/admin/config/')
|
||||||
this.recipeService.allSortedByCompany,
|
|
||||||
recipes => this.recipes = recipes
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.urlUtils.navigateTo("/admin/config")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.fetchCompanies()
|
||||||
|
// this.fetchRecipes()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchCompanies() {
|
||||||
|
this.subscribe(
|
||||||
|
this.companyService.all,
|
||||||
|
companies => this.companies = companies
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchRecipes() {
|
||||||
|
this.subscribe(
|
||||||
|
this.recipeService.allByCompany,
|
||||||
|
recipes => this.recipes = recipes,
|
||||||
|
true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRecipes() {
|
searchRecipes() {
|
||||||
|
@ -60,13 +78,16 @@ export class ListComponent extends ErrorHandlingComponent {
|
||||||
this.cdRef.detectChanges()
|
this.cdRef.detectChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.recipes
|
for (let recipeArray of this.recipes.values()) {
|
||||||
.flatMap(r => r.recipes)
|
recipeArray.forEach(recipe => this.recipeMatchesSearchQuery(recipe))
|
||||||
.forEach(r => this.recipeMatchesSearchQuery(r))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isCompanyHidden(companyRecipes: Recipe[]): boolean {
|
isCompanyHidden(company: Company): boolean {
|
||||||
return (this.searchQuery && this.searchQuery.length > 0) && companyRecipes.map(r => this.hiddenRecipes[r.id]).filter(r => !r).length <= 0
|
const companyRecipes = this.recipes.get(company.id);
|
||||||
|
return !(companyRecipes && companyRecipes.length >= 0) ||
|
||||||
|
this.searchQuery && this.searchQuery.length > 0 &&
|
||||||
|
companyRecipes.map(r => this.hiddenRecipes[r.id]).filter(r => !r).length <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
isLight(recipe: Recipe): boolean {
|
isLight(recipe: Recipe): boolean {
|
||||||
|
|
|
@ -3,86 +3,87 @@ import {ApiService} from '../../shared/service/api.service'
|
||||||
import {Observable} from 'rxjs'
|
import {Observable} from 'rxjs'
|
||||||
import {Recipe, RecipeStep} from '../../shared/model/recipe.model'
|
import {Recipe, RecipeStep} from '../../shared/model/recipe.model'
|
||||||
import {map} from 'rxjs/operators'
|
import {map} from 'rxjs/operators'
|
||||||
|
import {Company} from '../../shared/model/company.model';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class RecipeService {
|
export class RecipeService {
|
||||||
constructor(
|
constructor(
|
||||||
private api: ApiService
|
private api: ApiService
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
get all(): Observable<Recipe[]> {
|
get all(): Observable<Recipe[]> {
|
||||||
return this.api.get<Recipe[]>('/recipe')
|
return this.api.get<Recipe[]>('/recipe')
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllByName(name: string): Observable<Recipe[]> {
|
getAllByName(name: string): Observable<Recipe[]> {
|
||||||
return this.api.get<Recipe[]>(`/recipe?name=${name}`)
|
return this.api.get<Recipe[]>(`/recipe?name=${name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
get allSortedByCompany(): Observable<{ company: string, recipes: Recipe[] }[]> {
|
get allByCompany(): Observable<Map<number, Recipe[]>> {
|
||||||
return this.all.pipe(map(recipes => {
|
return this.all.pipe(map(recipes => {
|
||||||
const mapped = []
|
const map = new Map<number, Recipe[]>()
|
||||||
recipes.forEach(r => {
|
recipes.forEach(r => {
|
||||||
if (!mapped[r.company.id]) {
|
if (!map.has(r.company.id)) {
|
||||||
mapped[r.company.id] = {company: r.company.name, recipes: []}
|
map.set(r.company.id, [])
|
||||||
|
}
|
||||||
|
map.get(r.company.id).push(r)
|
||||||
|
})
|
||||||
|
return map
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
getById(id: number): Observable<Recipe> {
|
||||||
|
return this.api.get<Recipe>(`/recipe/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
save(name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, companyId: number): Observable<Recipe> {
|
||||||
|
const body = {name, description, color, gloss, sample, remark, companyId}
|
||||||
|
if (approbationDate) {
|
||||||
|
// @ts-ignore
|
||||||
|
body.approbationDate = approbationDate
|
||||||
}
|
}
|
||||||
mapped[r.company.id].recipes.push(r)
|
return this.api.post<Recipe>('/recipe', body)
|
||||||
})
|
|
||||||
return mapped.filter(e => e != null) // Filter to remove empty elements in the array that appears for some reason
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
getById(id: number): Observable<Recipe> {
|
|
||||||
return this.api.get<Recipe>(`/recipe/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
save(name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, companyId: number): Observable<Recipe> {
|
|
||||||
const body = {name, description, color, gloss, sample, remark, companyId}
|
|
||||||
if (approbationDate) {
|
|
||||||
// @ts-ignore
|
|
||||||
body.approbationDate = approbationDate
|
|
||||||
}
|
|
||||||
return this.api.post<Recipe>('/recipe', body)
|
|
||||||
}
|
|
||||||
|
|
||||||
update(id: number, name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, steps: Map<number, RecipeStep[]>) {
|
|
||||||
const body = {id, name, description, color, gloss, sample, remark, steps: []}
|
|
||||||
if (approbationDate) {
|
|
||||||
// @ts-ignore
|
|
||||||
body.approbationDate = approbationDate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
steps.forEach((groupSteps, groupId) => {
|
update(id: number, name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, steps: Map<number, RecipeStep[]>) {
|
||||||
const mappedGroupSteps = groupSteps.map(s => {
|
const body = {id, name, description, color, gloss, sample, remark, steps: []}
|
||||||
return {message: s.message, position: s.position}
|
if (approbationDate) {
|
||||||
})
|
// @ts-ignore
|
||||||
body.steps.push({groupId, steps: mappedGroupSteps})
|
body.approbationDate = approbationDate
|
||||||
})
|
}
|
||||||
|
|
||||||
return this.api.put<Recipe>('/recipe', body)
|
steps.forEach((groupSteps, groupId) => {
|
||||||
}
|
const mappedGroupSteps = groupSteps.map(s => {
|
||||||
|
return {message: s.message, position: s.position}
|
||||||
|
})
|
||||||
|
body.steps.push({groupId, steps: mappedGroupSteps})
|
||||||
|
})
|
||||||
|
|
||||||
updateExplorerModifications(id: number, notes: Map<number, string>, mixesLocationChange: Map<number, string>): Observable<void> {
|
return this.api.put<Recipe>('/recipe', body)
|
||||||
const body = {
|
|
||||||
recipeId: id,
|
|
||||||
notes: [],
|
|
||||||
mixesLocation: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notes.forEach((content, groupId) => {
|
updateExplorerModifications(id: number, notes: Map<number, string>, mixesLocationChange: Map<number, string>): Observable<void> {
|
||||||
body.notes.push({groupId, content})
|
const body = {
|
||||||
})
|
recipeId: id,
|
||||||
|
notes: [],
|
||||||
|
mixesLocation: []
|
||||||
|
}
|
||||||
|
|
||||||
mixesLocationChange.forEach((location, mixId) => {
|
notes.forEach((content, groupId) => {
|
||||||
body.mixesLocation.push({mixId, location})
|
body.notes.push({groupId, content})
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.api.put<void>('/recipe/public', body)
|
mixesLocationChange.forEach((location, mixId) => {
|
||||||
}
|
body.mixesLocation.push({mixId, location})
|
||||||
|
})
|
||||||
|
|
||||||
delete(id: number): Observable<void> {
|
return this.api.put<void>('/recipe/public', body)
|
||||||
return this.api.delete<void>(`/recipe/${id}`)
|
}
|
||||||
}
|
|
||||||
|
delete(id: number): Observable<void> {
|
||||||
|
return this.api.delete<void>(`/recipe/${id}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue