Skip to content

Commit

Permalink
order numeration in associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ицкович Алексей Анатольевич committed Feb 10, 2024
1 parent 4f94c61 commit 7d63879
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
36 changes: 20 additions & 16 deletions apps/configurator/src/app/components/footer/footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SaveAsFileDirective } from '../../directives/save-as-file/save-as-file.
import { PinsStateService } from '../../services/store/pins-state.service';
import { combineLatest, map, Observable } from 'rxjs';
import { AsyncPipe, NgIf } from '@angular/common';
import { Association, Rule } from '@configurator/shared';
import { Action, Association, Rule } from '@configurator/shared';
import { UploaderModule } from '@configurator/uploader';


Expand Down Expand Up @@ -66,8 +66,10 @@ export class FooterComponent {
elseBlock = `
} else {
${
// @ts-ignore
rule.elseBlock.filter(Boolean).map(a => ` ${a.template.replace('{0}', a.parameters[0])}`).join('\n')}`
rule.elseBlock.filter(Boolean).filter(Boolean)
.map(a => this.makeAction(a, associations))
.filter(Boolean)
.join('\n')}`
}

if(rule.expression && rule.actions.filter(Boolean).length) {
Expand All @@ -77,19 +79,7 @@ ${
${
rule.actions
.filter(Boolean)
.map(a => {
const index = associations.findIndex(association => association.uuid === a.parentId);
const hasAssociation = a.template.includes('{1}')
// TODO добавить сообщение об ошибке в форме (отсутствует ассоциация)
if (hasAssociation && index < 0) {
return null;
}
return ` ${
a.template
.replace('{1}', (2 + index).toString())
.replace('{0}', a.parameters[0].toString())}`
})
.map(a => this.makeAction(a, associations))
.filter(Boolean)
.join('\n')}${elseBlock
}
Expand All @@ -99,4 +89,18 @@ ${

return '';
}

private makeAction = (action: Action, associations: Association[]): string | null => {
const index = associations.findIndex(association => association.uuid === action.parentId);
const hasAssociation = action.template.includes('{1}')
// TODO добавить сообщение об ошибке в форме (отсутствует ассоциация)
if (hasAssociation && index < 0) {
return null;
}

return ` ${
action.template
.replace('{1}', (2 + index).toString())
.replace('{0}', action.parameters[0].toString())}`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ActionComponent implements OnInit, OnDestroy {
public onTouched = (): void => void 0;

public getTitle(option: Action, value: Action ): boolean {
return option?.parentId === value?.parentId;
return (option?.parentId + option?.title) === (value?.parentId + value?.title);
}

constructor(
Expand Down
16 changes: 5 additions & 11 deletions apps/configurator/src/app/services/store/pins-state.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Injectable } from '@angular/core';
import {
BehaviorSubject, config,
BehaviorSubject,
distinctUntilChanged,
filter,
first,
map,
Observable, ReplaySubject, startWith, Subject, takeUntil
Observable,
ReplaySubject,
} from 'rxjs';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { LocalStorageService } from './local-storage.service';
import { Association, PinConfig, BoardConfig, Rule, Action } from '@configurator/shared';
import { Pin } from '../../components/z-uno-shield/z-uno-shield.model';
import { Location } from '@angular/common';
import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from 'lz-string';
import { generate, GeneratedData } from '@configurator/arduino-code-gen';
import { HttpClient } from '@angular/common/http';
import { ServerSyncService } from './server-sync.service';


Expand Down Expand Up @@ -62,8 +61,8 @@ export class PinsStateService {

public associations(): Observable<Action[]> {
return this.boardConfig$.pipe(
map(config => config.associations.map(a => a.actions.map(act => ({...act, uuid: a.uuid}))).flat()
.map(({ title, ...other }, index ) => ({...other, title: `${title} ${index + 2}`}))),
map(config => config.associations.map((a, index) => a.actions.map(act => ({...act, uuid: a.uuid, index }))).flat()
.map(({ title, index, ...other } ) => ({...other, title: `${title} ${index + 2}`}))),
);
}
public get snapshot(): BoardConfig {
Expand All @@ -84,11 +83,6 @@ export class PinsStateService {
this.updateRoute();
}

public removeRule(id: string): void {
// const { rules, ...other } = this.snapshot;
// this._boardConfig$.next({...other, rules: rules.filter(rule => rule.id !== id)});
}

public patchDeviceConfig(pin: PinConfig, possiblePins: Pin[]): void {
const state = this._boardConfig$.value;
const value = state.pins;
Expand Down

0 comments on commit 7d63879

Please sign in to comment.