-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d78ce8d
commit 474bc0c
Showing
25 changed files
with
920 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...src/modules/account/components/role-form/portal-menu-item/portal-menu-item.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<div class="portal-menu-item flex gap-3 items-center" | ||
[formGroup]="form"> | ||
<span class="flex items-center gap-2"> | ||
Title: | ||
<editable (save)="save()"> | ||
<ng-template viewMode> | ||
<span class="text-bold">{{ form.controls.title.value }}</span> | ||
</ng-template> | ||
|
||
<ng-template editMode> | ||
<mix-input formControlName="title" | ||
style="width: 150px" | ||
editableOnEnter | ||
editableOnEscape> | ||
</mix-input></ng-template> | ||
</editable> | ||
</span> | ||
|
||
<span class="flex items-center gap-2"> | ||
Path: | ||
<editable (save)="save()"> | ||
<ng-template viewMode> | ||
<span class="text-bold">{{ | ||
form.controls.path.value || 'Empty path' | ||
}}</span> | ||
</ng-template> | ||
|
||
<ng-template editMode> | ||
<mix-input [autoCompleteItems]="FULL_MENU" | ||
formControlName="path" | ||
style="width: 150px" | ||
editableOnEnter | ||
editableOnEscape> | ||
</mix-input></ng-template> | ||
</editable> | ||
</span> | ||
|
||
<span class="flex items-center gap-2"> | ||
Icon: | ||
<editable (save)="save()"> | ||
<ng-template viewMode> | ||
<span *ngIf="form.controls?.icon?.value" | ||
class="material-symbols-outlined text-bold">{{ form.controls.icon.value }}</span> | ||
<span *ngIf="!form.controls?.icon?.value">No icon found</span> | ||
</ng-template> | ||
|
||
<ng-template editMode> | ||
<mix-input formControlName="icon" | ||
style="width: 150px" | ||
editableOnEnter | ||
editableOnEscape> | ||
</mix-input></ng-template> | ||
</editable> | ||
</span> | ||
|
||
<span class="flex items-center gap-2"> | ||
Priority: | ||
<editable (save)="save()"> | ||
<ng-template viewMode> | ||
<span class="text-bold">{{ form.controls.priority.value || 0 }}</span> | ||
</ng-template> | ||
|
||
<ng-template editMode> | ||
<mix-input-number type="number" | ||
[step]="1" | ||
formControlName="priority" | ||
style="width: 150px" | ||
editableOnEnter | ||
editableOnEscape> | ||
</mix-input-number></ng-template> | ||
</editable> | ||
</span> | ||
|
||
<div class="flex gap-1 items-center ms-3"> | ||
<mix-button type="danger" | ||
[iconBtn]="true" | ||
(click)="deleteMenu()" | ||
size="xs"><span class="material-symbols-outlined"> delete </span></mix-button> | ||
|
||
<mix-button *ngIf="item.portalMenuId === null" | ||
type="outline" | ||
[iconBtn]="true" | ||
(click)="showDialog(addNewMenuItem)" | ||
size="xs"><span class="material-symbols-outlined"> add </span></mix-button> | ||
</div> | ||
</div> | ||
|
||
<ng-template #addNewMenuItem | ||
let-observer> | ||
<div [formGroup]="addMenuForm"> | ||
<div>Update Portal Menu Item:</div> | ||
|
||
<span class="content-label mt-3">Menu title</span> | ||
<mix-input formControlName="title" | ||
placeHolder="Menu title"></mix-input> | ||
<mix-form-error formControlName="title"></mix-form-error> | ||
|
||
<span class="content-label mt-3">Path</span> | ||
<mix-input [autoCompleteItems]="FULL_MENU" | ||
formControlName="path" | ||
placeHolder="Admin path url"></mix-input> | ||
|
||
<span class="content-label mt-3">Icon</span> | ||
<span class="content-sub-description">We use Google Symbol as icon, please | ||
<a href="https://fonts.google.com/icons" | ||
tuiLink | ||
target="_blank">visit here</a> | ||
to get the correct icon name</span> | ||
|
||
<mix-input class="mt-1" | ||
formControlName="icon" | ||
placeHolder="Icon"></mix-input> | ||
|
||
<div class="flex justify-content-end mt-3"> | ||
<mix-button type="outline" | ||
(click)="observer.complete()">Cancel</mix-button> | ||
|
||
<mix-button class="ms-2" | ||
(click)="createMenu(observer)">Create</mix-button> | ||
</div> | ||
</div> | ||
</ng-template> |
5 changes: 5 additions & 0 deletions
5
...src/modules/account/components/role-form/portal-menu-item/portal-menu-item.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.portal-menu-item { | ||
padding: 8px; | ||
border-radius: 4px; | ||
border: 1px solid var(--border-color-default); | ||
} |
150 changes: 150 additions & 0 deletions
150
...e/src/modules/account/components/role-form/portal-menu-item/portal-menu-item.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
EventEmitter, | ||
Input, | ||
OnInit, | ||
Output, | ||
inject, | ||
} from '@angular/core'; | ||
import { | ||
FormControl, | ||
FormGroup, | ||
ReactiveFormsModule, | ||
Validators, | ||
} from '@angular/forms'; | ||
import { MixDynamicData, PortalMenu } from '@mixcore/lib/model'; | ||
import { MixApiFacadeService } from '@mixcore/share/api'; | ||
import { FULL_MENU } from '@mixcore/share/auth'; | ||
import { FormHelper } from '@mixcore/share/form'; | ||
import { Utils } from '@mixcore/share/utils'; | ||
import { MixButtonComponent } from '@mixcore/ui/button'; | ||
import { MixInputComponent } from '@mixcore/ui/input'; | ||
import { MixInputNumberComponent } from '@mixcore/ui/input-number'; | ||
import { ModalService } from '@mixcore/ui/modal'; | ||
import { EditModeDirective, EditableComponent } from '@ngneat/edit-in-place'; | ||
import { HotToastService } from '@ngneat/hot-toast'; | ||
import { TuiDialogContext, TuiDialogService } from '@taiga-ui/core'; | ||
import { PolymorpheusContent } from '@tinkoff/ng-polymorpheus'; | ||
import { map, switchMap } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'mix-portal-menu-item', | ||
templateUrl: './portal-menu-item.component.html', | ||
styleUrls: ['./portal-menu-item.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
MixInputComponent, | ||
MixButtonComponent, | ||
EditableComponent, | ||
EditModeDirective, | ||
EditModeDirective, | ||
ReactiveFormsModule, | ||
MixInputNumberComponent, | ||
], | ||
}) | ||
export class PortalMenuItemComponent implements OnInit { | ||
FULL_MENU = inject(FULL_MENU).map((x) => x.url); | ||
MIX_API = inject(MixApiFacadeService); | ||
TOAST = inject(HotToastService); | ||
dialog = inject(TuiDialogService); | ||
DB_NAME = 'PortalMenu'; | ||
modal = inject(ModalService); | ||
|
||
@Input() item!: PortalMenu; | ||
@Output() portalMenuAdded = new EventEmitter<PortalMenu>(); | ||
@Output() portalMenuDeleted = new EventEmitter<PortalMenu>(); | ||
|
||
defaultFormValue: Record<string, string | null> = {}; | ||
form = new FormGroup({ | ||
title: new FormControl('', Validators.required), | ||
path: new FormControl('', Validators.required), | ||
icon: new FormControl('', Validators.required), | ||
priority: new FormControl(), | ||
}); | ||
|
||
public addMenuForm = new FormGroup({ | ||
title: new FormControl('', Validators.required), | ||
path: new FormControl('', Validators.required), | ||
icon: new FormControl('', Validators.required), | ||
}); | ||
|
||
ngOnInit() { | ||
this.form.patchValue(this.item); | ||
this.defaultFormValue = this.form.getRawValue(); | ||
} | ||
|
||
save() { | ||
if (FormHelper.validateForm(this.form)) { | ||
if (!Utils.isDifferent(this.defaultFormValue, this.form.getRawValue())) | ||
return; | ||
|
||
this.MIX_API.databaseApi | ||
.saveData(this.DB_NAME, this.item.id, { | ||
...this.item, | ||
...(this.form.getRawValue() as unknown as MixDynamicData), | ||
}) | ||
.pipe( | ||
this.TOAST.observe({ | ||
loading: 'Saving...', | ||
success: 'Successfully apply your change', | ||
error: 'Something error, please try again', | ||
}) | ||
) | ||
.subscribe(() => { | ||
this.defaultFormValue = this.form.getRawValue(); | ||
}); | ||
} | ||
} | ||
|
||
createMenu(dialog: any) { | ||
if (FormHelper.validateForm(this.form)) { | ||
this.MIX_API.databaseApi | ||
.saveData(this.DB_NAME, -1, { | ||
...(this.addMenuForm.getRawValue() as unknown as MixDynamicData), | ||
portalMenuId: this.item.id, | ||
role: this.item.role, | ||
}) | ||
.pipe( | ||
switchMap((item) => { | ||
return this.MIX_API.databaseApi | ||
.associateDb(this.DB_NAME, item.id!, this.DB_NAME, this.item.id) | ||
.pipe(map(() => item)); | ||
}), | ||
this.TOAST.observe({ | ||
loading: 'Creating...', | ||
success: 'Successfully apply your change', | ||
error: 'Something error, please try again', | ||
}) | ||
) | ||
.subscribe((result) => { | ||
this.portalMenuAdded.emit(result as unknown as PortalMenu); | ||
dialog.complete(); | ||
}); | ||
} | ||
} | ||
|
||
deleteMenu() { | ||
this.modal.asKForAction('Are you sure to delete this portal menu ?', () => { | ||
this.MIX_API.databaseApi | ||
.deleteData(this.DB_NAME, this.item.id) | ||
.pipe( | ||
this.TOAST.observe({ | ||
loading: 'Deleting...', | ||
success: 'Successfully apply your change', | ||
error: 'Something error, please try again', | ||
}) | ||
) | ||
.subscribe(() => { | ||
this.portalMenuDeleted.emit(this.item); | ||
}); | ||
}); | ||
} | ||
|
||
showDialog(content: PolymorpheusContent<TuiDialogContext>): void { | ||
this.dialog.open(content, { size: 'auto' }).subscribe(); | ||
} | ||
} |
Oops, something went wrong.
474bc0c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mix-portal-angular – ./
mix-portal-angular-git-master-phongcaos-projects.vercel.app
mix-portal-angular-phongcaos-projects.vercel.app
p4ps-portal.vercel.app