add wrapper and finishing promotion

This commit is contained in:
Zuhdan Ubay 2020-05-20 08:33:11 +07:00
parent 068f8dda2f
commit eca4c23fb9
29 changed files with 1172 additions and 71 deletions

View file

@ -20,11 +20,15 @@ import {
NbToastrModule,
NbWindowModule,
} from '@nebular/theme';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
HttpClientModule,
AppRoutingModule,

View file

@ -4,19 +4,19 @@ export const MENU_ITEMS: NbMenuItem[] = [
{
title: 'Service Agreement',
icon: 'edit-2-outline',
link: '/pages/tbd',
link: '/pages/service-agreement',
home: false,
},
{
title: 'Partner Price',
icon: 'keypad-outline',
link: '/pages/tbd',
link: '/pages/partner-price',
home: false,
},
{
title: 'Billing',
icon: 'shopping-cart-outline',
link: '/pages/tbd',
link: '/pages/billing',
home: false,
},
{
@ -28,7 +28,7 @@ export const MENU_ITEMS: NbMenuItem[] = [
{
title: 'Partner Branch',
icon: 'shuffle-2-outline',
link: '/pages/tbd',
link: '/pages/partner-branch',
home: false,
},
];

View file

@ -4,6 +4,7 @@ import {NgModule} from '@angular/core';
import {PagesComponent} from './pages.component';
import {NotFoundComponent} from './miscellaneous/not-found/not-found.component';
import {PromotionComponent} from './promotion/promotion.component';
import { PartnerPriceComponent } from './partner-price/partner-price.component';
const routes: Routes = [{
path: '',
@ -14,7 +15,19 @@ const routes: Routes = [{
component: PromotionComponent,
},
{
path: 'tbd',
path: 'partner-price',
component: PartnerPriceComponent,
},
{
path: 'service-agreement',
component: NotFoundComponent,
},
{
path: 'partner-branch',
component: NotFoundComponent,
},
{
path: 'billing',
component: NotFoundComponent,
},
],

View file

@ -0,0 +1,85 @@
<div class="row">
<div class="col-md-4">
<form>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Partner Code</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.customerID">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">User Id</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.customerID">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Promo Type</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.promotionType">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Periode </label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validDay">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Coupon Code</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.code">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Valid Start</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validFrom">
</div>
</form>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="exampleInputPassword1" class="label">Valid End</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validTo">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Max. Promo</label>
<input type="number" nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.maximumDiscount">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Quota per User</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.maximumPerUser">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">User Type</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.customerType">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Coverage Pickup</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.coverage">
</div>
</div>
<div class="col-md-4">
<form>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Product</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.product">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (IDR)</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (%)</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Max. Promo</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.maximumDiscountValue">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Budget</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.maximumDiscount">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Quota</label>
<input type="number" nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.quota">
</div>
<button (click)="onSubmit()" type="submit" nbButton status="primary">Submit</button>
</form>
</div>
</div>

View file

@ -0,0 +1,15 @@
nb-checkbox {
margin-bottom: 1rem;
}
.form-inline [fullWidth] {
flex: 1;
}
.form-inline > * {
margin: 0 1.5rem 1.5rem 0;
}
nb-card.inline-form-card nb-card-body {
padding-bottom: 0;
}

View file

@ -0,0 +1,30 @@
import { Component, Inject, Input } from '@angular/core';
import { NbWindowRef, NB_WINDOW_CONTEXT } from '@nebular/theme';
import { PromotionList } from '../../../@core/data/promotion';
import { PartnerPriceService } from '../partner-price.service';
@Component({
selector: 'ngx-partner-price-detail',
templateUrl: './partner-price-detail.component.html',
styleUrls: ['partner-price-detail.component.scss'],
})
export class PartnerPriceDetailComponent {
@Input() data: PromotionList;
constructor(private service: PartnerPriceService, public windowRef: NbWindowRef, @Inject(NB_WINDOW_CONTEXT) context) {
if (context != null) {
this.data = Object.assign({}, context.data);
}
}
onSubmit(){
this.service.postPromotion(this.data).subscribe((value) => {
this.close();
});
}
close() {
this.windowRef.close();
}
}

View file

@ -0,0 +1,11 @@
<nb-card>
<nb-card-header>
Partner Price
</nb-card-header>
<nb-card-body>
<ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"
(createConfirm)="onCreateConfirm($event)" (userRowSelect)="openWindowForm($event)">
</ng2-smart-table>
</nb-card-body>
</nb-card>

View file

@ -0,0 +1,7 @@
@import '../../@theme/styles/themes';
@include nb-install-component() {
nb-card {
transform: translate3d(0, 0, 0);
}
}

View file

@ -0,0 +1,94 @@
import { Component, OnInit } from '@angular/core';
import { PromotionList } from '../../@core/data/promotion';
import { PartnerPriceService } from './partner-price.service';
import { PartnerPriceDetailComponent } from './partner-price-detail/partner-price-detail.component';
import { NbWindowService } from '@nebular/theme';
@Component({
selector: 'ngx-partner-price',
templateUrl: './partner-price.component.html',
styleUrls: ['./partner-price.component.scss'],
})
export class PartnerPriceComponent implements OnInit {
settings = {
mode: 'inline',
add: {
addButtonContent: '<i class="nb-plus"></i>',
createButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmCreate: true,
},
edit: {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
confirmDelete: true,
},
columns: {
code: {
title: 'Coupon Code',
type: 'string',
},
validDay: {
title: 'Period',
type: 'string',
},
validFrom: {
title: 'Valid Start',
type: 'string',
},
validTo: {
title: 'Valid End',
type: 'string',
},
},
};
source: PromotionList[] = [];
constructor(private service: PartnerPriceService, private windowService: NbWindowService) {
}
ngOnInit(): void {
this.initData();
}
initData(){
this.service.getPromotion().subscribe((result) => {
this.source = Object.assign([], result);
});
}
onCreateConfirm(event) {
if (window.confirm('Are you sure you want to save?')) {
event.newData.status = 1;
this.service.postPromotion(event.newData).subscribe((value) => {
this.initData();
});
event.confirm.resolve(event.newData);
} else {
event.confirm.reject();
}
}
onDeleteConfirm(event): void {
if (window.confirm('Are you sure you want to delete?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
openWindowForm(event) {
this.windowService.open(PartnerPriceDetailComponent, {
title: 'Promotion Detail',
context: {
data: event.data,
},
});
}
}

View file

@ -0,0 +1,43 @@
import { NgModule } from '@angular/core';
import {
NbCardModule,
NbIconModule,
NbInputModule,
NbTreeGridModule,
NbButtonModule,
NbCheckboxModule,
NbRadioModule} from '@nebular/theme';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { ThemeModule } from '../../@theme/theme.module';
import { PartnerPriceComponent } from './partner-price.component';
import { PartnerPriceService } from './partner-price.service';
import { PartnerPriceDetailComponent } from './partner-price-detail/partner-price-detail.component';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
NbCardModule,
NbTreeGridModule,
NbIconModule,
NbInputModule,
ThemeModule,
NbButtonModule,
NbRadioModule,
NbCheckboxModule,
Ng2SmartTableModule,
FormsModule,
],
declarations: [
PartnerPriceComponent,
PartnerPriceDetailComponent,
],
providers: [
PartnerPriceService,
PartnerPriceDetailComponent,
],
entryComponents: [
PartnerPriceDetailComponent,
],
})
export class PromotionModule { }

View file

@ -0,0 +1,55 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { HttpErrorResponse } from '@angular/common/http';
import { PromotionList } from '../../@core/data/promotion';
@Injectable({
providedIn: 'root',
})
export class PartnerPriceService {
constructor(private http: HttpClient) {
}
getPromotion(): Observable<any> {
const url = 'http://localhost:8011/api/promotions/all';
return this.http.get(url).pipe(
map(this.extractData),
catchError(this.handleError),
);
}
postPromotion(data: PromotionList): Observable<any> {
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'X-Requested-Method': 'POST',
});
const options = { headers: headers };
const url = 'http://localhost:8011/api/promotions/add';
return this.http.post(url, JSON.stringify(data), options).pipe(
catchError(this.handleError),
);
}
private extractData(body: any): PromotionList[] {
return Object.assign(body.promotionList);
}
private handleError(error: HttpErrorResponse | any) {
let errMsg: string;
let errObj: any;
if (error instanceof HttpErrorResponse) {
const err = error.message || JSON.stringify(error);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
errObj = error.error.message;
} else {
errMsg = error.message ? error.message : error.toString();
const body = error.message || '';
errObj = body;
}
return throwError(errObj);
}
}

View file

@ -1,85 +1,81 @@
<div class="row">
<div class="col-md-4">
<form>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Partner Code</label>
<input nbInput fullWidth id="exampleInputEmail1" value="{{data.customerID}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">User Id</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.customerID}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Promo Type</label>
<input nbInput fullWidth id="exampleInputEmail1" value="{{data.promotionType}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Periode </label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.validDay}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Coupon Code</label>
<input nbInput fullWidth id="exampleInputEmail1" value="{{data.code}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Valid Start</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.validFrom}}">
</div>
</form>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Partner Code</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.customerID">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">User Id</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.customerID">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Promo Type</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.promotionType">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Periode </label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validDay">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Coupon Code</label>
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.code">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Valid Start</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validFrom">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="exampleInputPassword1" class="label">Valid End</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.validTo}}">
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.validTo">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.value}}">
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Max. Promo</label>
<input nbInput fullWidth id="exampleInputEmail1" value="{{data.maximumDiscount}}">
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.maximumDiscount">
</div>
<div class="form-group">
<label for="exampleInputEmail1" class="label">Quota per User</label>
<input nbInput fullWidth id="exampleInputEmail1" value="{{data.maximumPerUser}}">
<input nbInput fullWidth id="exampleInputEmail1" [(ngModel)]="data.maximumPerUser">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">User Type</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.customerType}}">
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.customerType">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Coverage Pickup</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.coverage}}">
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.coverage">
</div>
</div>
<div class="col-md-4">
<form>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Product</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.product}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (IDR)</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.value}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (%)</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.value}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Max. Promo</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.maximumDiscountValue}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Budget</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.maximumDiscount}}">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Quota</label>
<input nbInput fullWidth id="exampleInputPassword1" value="{{data.quota}}">
</div>
<button type="submit" nbButton status="primary">Submit</button>
</form>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Product</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.product">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (IDR)</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Promo (%)</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.value">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Max. Promo</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.maximumDiscountValue">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Budget</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.maximumDiscount">
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="label">Quota</label>
<input nbInput fullWidth id="exampleInputPassword1" [(ngModel)]="data.quota">
</div>
<button (click)="onSubmit()" type="submit" nbButton status="primary">Submit</button>
</div>
</div>

View file

@ -1,6 +1,8 @@
import { Component, Inject } from '@angular/core';
import { Component, Inject, Input } from '@angular/core';
import { NbWindowRef, NB_WINDOW_CONTEXT } from '@nebular/theme';
import { PromotionList } from '../../../@core/data/promotion';
import { PromotionService } from '../promotion.service';
import { NgForm } from '@angular/forms';
@Component({
selector: 'ngx-promotion-detail',
@ -9,14 +11,20 @@ import { PromotionList } from '../../../@core/data/promotion';
})
export class PromotionDetailComponent {
data: PromotionList;
@Input() data: PromotionList;
constructor(public windowRef: NbWindowRef, @Inject(NB_WINDOW_CONTEXT) context) {
constructor(private service: PromotionService, public windowRef: NbWindowRef, @Inject(NB_WINDOW_CONTEXT) context) {
if (context != null) {
this.data = Object.assign({}, context.data);
}
}
onSubmit(){
this.service.postPromotion(this.data).subscribe((value) => {
this.close();
});
}
close() {
this.windowRef.close();
}

View file

@ -5,7 +5,8 @@
<nb-card-body>
<ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"
(createConfirm)="onCreateConfirm($event)" (userRowSelect)="openWindowForm($event)">
(createConfirm)="onCreateConfirm($event)" (editConfirm)="onCreateConfirm($event)"
(userRowSelect)="openWindowForm($event)">
</ng2-smart-table>
</nb-card-body>
</nb-card>

View file

@ -22,6 +22,7 @@ export class PromotionComponent implements OnInit {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmSave: true,
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
@ -54,6 +55,10 @@ export class PromotionComponent implements OnInit {
}
ngOnInit(): void {
this.initData();
}
initData(){
this.service.getPromotion().subscribe((result) => {
this.source = Object.assign([], result);
});
@ -61,7 +66,10 @@ export class PromotionComponent implements OnInit {
onCreateConfirm(event) {
if (window.confirm('Are you sure you want to save?')) {
this.service.postPromotion(event.newData).subscribe();
event.newData.status = 1;
this.service.postPromotion(event.newData).subscribe((value) => {
this.initData();
});
event.confirm.resolve(event.newData);
} else {
event.confirm.reject();

View file

@ -6,13 +6,15 @@ import {
NbTreeGridModule,
NbButtonModule,
NbCheckboxModule,
NbRadioModule} from '@nebular/theme';
NbRadioModule
} from '@nebular/theme';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { ThemeModule } from '../../@theme/theme.module';
import { PromotionComponent } from './promotion.component';
import { PromotionService } from './promotion.service';
import { PromotionDetailComponent } from './promotion-detail/promotion-detail.component';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
@ -25,6 +27,7 @@ import { PromotionDetailComponent } from './promotion-detail/promotion-detail.co
NbRadioModule,
NbCheckboxModule,
Ng2SmartTableModule,
FormsModule,
],
declarations: [
PromotionComponent,