-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal-form): create modal and renamend files
- Loading branch information
1 parent
3f7f564
commit e1f80e9
Showing
16 changed files
with
340 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './modal-form-app/modal-form-app.component'; |
36 changes: 36 additions & 0 deletions
36
src/app/core/components/modal-form-app/modal-form-app.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,36 @@ | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left">{{ data?.id ? 'Edit ' + data?.name : 'Create' }}</h4> | ||
<button type="button" class="close pull-right" aria-label="Close" (click)="bsModalRef.hide()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<form [formGroup]="dataForm"> | ||
<div class="form-group"> | ||
<label for="input-name">Name</label> | ||
<input | ||
class="form-control" | ||
type="text" | ||
name="name" | ||
formControlName="name" | ||
id="input-name" | ||
required | ||
> | ||
</div> | ||
<div class="form-group"> | ||
<label for="input-url">URL</label> | ||
<input | ||
class="form-control" | ||
type="url" | ||
name="url" | ||
formControlName="url" | ||
id="input-url" | ||
required | ||
> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" (click)="bsModalRef.hide()">Cancel</button> | ||
<button type="submit" class="btn btn-info" (click)="submitForm($event)">Save</button> | ||
</div> |
29 changes: 29 additions & 0 deletions
29
src/app/core/components/modal-form-app/modal-form-app.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,29 @@ | ||
.modal-dialog { | ||
max-width: 400px; | ||
} | ||
.modal-header, .modal-body, .modal-footer { | ||
padding: 20px 30px; | ||
} | ||
.modal-content { | ||
border-radius: 3px; | ||
} | ||
.modal-footer { | ||
background: #ecf0f1; | ||
border-radius: 0 0 3px 3px; | ||
} | ||
.modal-title { | ||
display: inline-block; | ||
} | ||
.form-control { | ||
border-radius: 2px; | ||
box-shadow: none; | ||
border-color: #dddddd; | ||
} | ||
|
||
.btn { | ||
border-radius: 2px; | ||
min-width: 100px; | ||
} | ||
form label { | ||
font-weight: normal; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/app/core/components/modal-form-app/modal-form-app.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,83 @@ | ||
// Angular Imports | ||
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
|
||
// External Libs | ||
import { Subject, Subscription } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
|
||
// Models Imports | ||
import { IManageApp } from '@app/core/models'; | ||
|
||
// Services Imports | ||
import { ManageAppService } from '@app/core/services'; | ||
|
||
@Component({ | ||
selector: 'webae-modal-form-app', | ||
templateUrl: './modal-form-app.component.html', | ||
styleUrls: ['./modal-form-app.component.scss'], | ||
providers: [ManageAppService] | ||
}) | ||
export class ModalFormAppComponent implements OnInit, OnDestroy { | ||
|
||
@Input() data: IManageApp; | ||
|
||
@Output() submitData: EventEmitter<IManageApp> = new EventEmitter<IManageApp>(); | ||
|
||
dataForm = new FormGroup({ | ||
name: new FormControl('', [Validators.required]), | ||
url: new FormControl('', [Validators.required]), | ||
}); | ||
|
||
private ngUnSubscribe: Subject<Subscription> = new Subject<Subscription>(); | ||
|
||
constructor( | ||
public bsModalRef: BsModalRef, | ||
public manageAppService: ManageAppService | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.dataForm.patchValue({...this.data}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.ngUnSubscribe.next(); | ||
this.ngUnSubscribe.complete(); | ||
} | ||
|
||
submitForm(event: MouseEvent): void { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
if (!this.dataForm.valid) { | ||
return; | ||
} | ||
|
||
const data: IManageApp = { ...this.data, ...this.dataForm.value }; | ||
|
||
if (this.data && this.data.id) { | ||
this.updateManageApp(data); | ||
} else { | ||
this.createManageApp(data); | ||
} | ||
|
||
} | ||
|
||
private createManageApp(manageApp: IManageApp): void { | ||
this.manageAppService.create(manageApp) | ||
.pipe(takeUntil(this.ngUnSubscribe)) | ||
.subscribe(res => { | ||
console.log(res); | ||
}); | ||
} | ||
|
||
private updateManageApp(manageApp: IManageApp): void { | ||
this.manageAppService.update(manageApp) | ||
.pipe(takeUntil(this.ngUnSubscribe)) | ||
.subscribe(res => { | ||
console.log(res); | ||
}); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
// Angular Imports | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
|
||
// Modules Imports | ||
import { CoreRoutingModule } from './core-routing.module'; | ||
|
||
// LIB Data Table Import | ||
import { DataTableModule } from '@projects/data-table'; | ||
|
||
// Components Imports | ||
import { CoreComponent } from './core.component'; | ||
import { UrlListComponent } from './pages/url-list/url-list.component'; | ||
import { DataTableModule } from '@projects/data-table'; | ||
import { ManageAppListComponent } from '@app/core/pages'; | ||
import { ModalFormAppComponent } from './components'; | ||
|
||
// Services Imports | ||
import { ManageAppService } from '@app/core/services'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
CoreComponent, | ||
UrlListComponent | ||
ManageAppListComponent, | ||
ModalFormAppComponent | ||
], | ||
imports: [ | ||
CommonModule, | ||
ReactiveFormsModule, | ||
CoreRoutingModule, | ||
DataTableModule | ||
] | ||
], | ||
providers: [ManageAppService] | ||
}) | ||
export class CoreModule { } |
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,6 @@ | ||
export interface IManageApp { | ||
id?: string; | ||
name: string; | ||
url: string; | ||
is_online?: boolean; | ||
} |
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 @@ | ||
export * from './manage-app-list/manage-app-list.component'; |
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.
124 changes: 124 additions & 0 deletions
124
src/app/core/pages/manage-app-list/manage-app-list.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,124 @@ | ||
// Angular Imports | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
|
||
// External Libs | ||
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | ||
|
||
// Lib Data Table Imports | ||
import { EColumnType, IColumn } from '@projects/data-table'; | ||
|
||
// Services Imports | ||
import { ElectronService } from '@app/services'; | ||
|
||
// Components Imports | ||
import { ModalFormAppComponent } from '@app/core/components'; | ||
|
||
// Models Imports | ||
import { IManageApp } from '@app/core/models'; | ||
import { Subject, Subscription } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { ManageAppService } from '@app/core/services'; | ||
|
||
@Component({ | ||
selector: 'webae-manage-app-list', | ||
templateUrl: './manage-app-list.component.html', | ||
styleUrls: ['./manage-app-list.component.scss'] | ||
}) | ||
export class ManageAppListComponent implements OnInit, OnDestroy { | ||
|
||
// Data Models | ||
data: IManageApp[] = []; | ||
dataColumns: IColumn[] = [ | ||
{ type: EColumnType.checkbox }, | ||
{ label: 'Name', field: 'name' }, | ||
{ label: 'URL', field: 'url' }, | ||
{ label: 'Is Online', field: 'is_online' }, | ||
{ | ||
label: 'Actions', | ||
type: EColumnType.actions, | ||
actions: [ | ||
{ | ||
label: 'Edit', | ||
icon: 'fas fa-pen', | ||
command: (e) => { | ||
e.originalEvent.preventDefault(); | ||
e.originalEvent.stopPropagation(); | ||
this.openModal(e.item); | ||
} | ||
}, | ||
{ | ||
label: 'Delete', | ||
icon: 'fas fa-trash', | ||
command: (e) => { | ||
e.originalEvent.preventDefault(); | ||
e.originalEvent.stopPropagation(); | ||
} | ||
}, | ||
{ | ||
label: 'Open', | ||
icon: 'fas fa-globe', | ||
command: (e) => { | ||
e.originalEvent.preventDefault(); | ||
e.originalEvent.stopPropagation(); | ||
console.log(e); | ||
this.openUrl(e.item.url); | ||
} | ||
}, | ||
] | ||
}, | ||
]; | ||
|
||
// Modal Ref | ||
bsModalRef: BsModalRef; | ||
|
||
private ngUnSubscribe: Subject<Subscription> = new Subject<Subscription>(); | ||
|
||
constructor( | ||
private electronService: ElectronService, | ||
private modalService: BsModalService, | ||
private manageAppService: ManageAppService | ||
) { } | ||
|
||
ngOnInit(): void { | ||
this.getManageAPPList(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.ngUnSubscribe.next(); | ||
this.ngUnSubscribe.complete(); | ||
} | ||
|
||
createManageApp(event: MouseEvent): void { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.openModal(); | ||
} | ||
|
||
private openUrl(url: string): void { | ||
this.electronService.ipcRenderer.invoke('url-channel', { url }) | ||
.then((result) => { | ||
console.log(result); | ||
}); | ||
} | ||
|
||
private openModal(item?: IManageApp): void { | ||
const initialState = { data: item }; | ||
this.bsModalRef = this.modalService.show(ModalFormAppComponent, {initialState}); | ||
|
||
(this.bsModalRef.content as ModalFormAppComponent).submitData | ||
.pipe(takeUntil(this.ngUnSubscribe)) | ||
.subscribe((data: IManageApp) => { | ||
console.log(data); | ||
}); | ||
} | ||
|
||
private getManageAPPList(): void { | ||
this.manageAppService.list() | ||
.pipe(takeUntil(this.ngUnSubscribe)) | ||
.subscribe(res => { | ||
this.data = [...res]; | ||
}); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.