Header / Footer editor added - Right now linked to products permission, which should be changed
This commit is contained in:
parent
77fb8e8428
commit
8db9a7d757
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#scp knox:csv.tar.zip /home/tanshu/Programming/csv
|
||||
cd /home/tanshu/Programming/csv
|
||||
#tar xvf csv.tar.zip
|
||||
@ -33,7 +34,7 @@ docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --en
|
||||
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy reprints(id, user_id, date, voucher_id) from /mnt/u-Reprints.csv"'
|
||||
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy settings(id, name, data) from /mnt/v-Settings.csv"'
|
||||
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty -c "\copy settlements(id, voucher_id, settled, amount) from /mnt/w-VoucherSettlements.csv"'
|
||||
docker run -it -v /home/tanshu/Programming/barker/DB:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty < /mnt/z-RenamePermissions.sql'
|
||||
docker run -it -v /home/tanshu/Programming/csv:/mnt --link postgres:db --rm --env PGPASSWORD="123456" postgres:alpine bash -c 'psql -h db -U postgres petty < /mnt/z-RenamePermissions.sql'
|
||||
|
||||
# Show the file in code to see the hidden chars
|
||||
# od -t c ~/Programming/csv/n-Printers.csv
|
||||
|
@ -9,6 +9,7 @@ from .db.session import engine
|
||||
from .routers import (
|
||||
device,
|
||||
guest_book,
|
||||
header_footer,
|
||||
login,
|
||||
menu_category,
|
||||
modifier,
|
||||
@ -63,6 +64,7 @@ app.include_router(menu_category.router, prefix="/api/menu-categories", tags=["p
|
||||
app.include_router(product.router, prefix="/api/products", tags=["products"])
|
||||
app.include_router(device.router, prefix="/api/devices", tags=["devices"])
|
||||
app.include_router(sale_category.router, prefix="/api/sale-categories", tags=["products"])
|
||||
app.include_router(header_footer.router, prefix="/api/header-footer", tags=["products"])
|
||||
|
||||
app.include_router(section.router, prefix="/api/sections", tags=["sections"])
|
||||
app.include_router(section_printer.router, prefix="/api/section-printers", tags=["section-printers"])
|
||||
|
58
barker/barker/routers/header_footer.py
Normal file
58
barker/barker/routers/header_footer.py
Normal file
@ -0,0 +1,58 @@
|
||||
import barker.schemas.header_footer as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionLocal
|
||||
from ..models.master import DbSetting
|
||||
from ..schemas.auth import UserToken
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# Dependency
|
||||
def get_db():
|
||||
try:
|
||||
db = SessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.get("")
|
||||
def get(
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
return [
|
||||
{"id": item.id, "name": item.name, "text": item.data["Text"]}
|
||||
for item in db.query(DbSetting).filter(DbSetting.name.in_(["Header", "Footer"])).all()
|
||||
]
|
||||
|
||||
|
||||
@router.post("")
|
||||
def save(
|
||||
data: schemas.HeaderFooter,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
):
|
||||
try:
|
||||
item: DbSetting = db.query(DbSetting).filter(DbSetting.id == data.id_, DbSetting.name == data.name).first()
|
||||
item.data = {"Text": data.text}
|
||||
db.commit()
|
||||
return [
|
||||
{"id": item.id, "name": item.name, "text": item.data["Text"]}
|
||||
for item in db.query(DbSetting).filter(DbSetting.name.in_(["Header", "Footer"])).all()
|
||||
]
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
14
barker/barker/schemas/header_footer.py
Normal file
14
barker/barker/schemas/header_footer.py
Normal file
@ -0,0 +1,14 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from . import to_camel
|
||||
|
||||
|
||||
class HeaderFooter(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
text: str
|
||||
|
||||
class Config:
|
||||
alias_generator = to_camel
|
@ -38,6 +38,10 @@ const routes: Routes = [
|
||||
path: 'guest-book',
|
||||
loadChildren: () => import('./guest-book/guest-book.module').then((mod) => mod.GuestBookModule),
|
||||
},
|
||||
{
|
||||
path: 'header-footer',
|
||||
loadChildren: () => import('./header-footer/header-footer.module').then((mod) => mod.HeaderFooterModule),
|
||||
},
|
||||
{
|
||||
path: 'modifiers',
|
||||
loadChildren: () => import('./modifiers/modifiers.module').then((mod) => mod.ModifiersModule),
|
||||
|
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HeaderFooterResolver } from './header-footer-resolver.service';
|
||||
|
||||
describe('HeaderFooterResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [HeaderFooterResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([HeaderFooterResolver], (service: HeaderFooterResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { HeaderFooter } from './header-footer';
|
||||
import { HeaderFooterService } from './header-footer.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class HeaderFooterResolver implements Resolve<HeaderFooter[]> {
|
||||
constructor(private ser: HeaderFooterService) {}
|
||||
|
||||
resolve(): Observable<HeaderFooter[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
import { HeaderFooterRoutingModule } from './header-footer-routing.module';
|
||||
|
||||
describe('HeaderFooterRoutingModule', () => {
|
||||
let headerFooterRoutingModule: HeaderFooterRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
headerFooterRoutingModule = new HeaderFooterRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(headerFooterRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
40
bookie/src/app/header-footer/header-footer-routing.module.ts
Normal file
40
bookie/src/app/header-footer/header-footer-routing.module.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { HeaderFooterResolver } from './header-footer-resolver.service';
|
||||
import { HeaderFooterComponent } from './header-footer.component';
|
||||
|
||||
const headerRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: HeaderFooterComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
list: HeaderFooterResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: HeaderFooterComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
list: HeaderFooterResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(headerRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [HeaderFooterResolver],
|
||||
})
|
||||
export class HeaderFooterRoutingModule {}
|
3
bookie/src/app/header-footer/header-footer.component.css
Normal file
3
bookie/src/app/header-footer/header-footer.component.css
Normal file
@ -0,0 +1,3 @@
|
||||
.example-card {
|
||||
max-width: 400px;
|
||||
}
|
45
bookie/src/app/header-footer/header-footer.component.html
Normal file
45
bookie/src/app/header-footer/header-footer.component.html
Normal file
@ -0,0 +1,45 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Header / Footer</mat-card-title>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Header / Footer</mat-label>
|
||||
<mat-select
|
||||
placeholder="Header / Footer"
|
||||
formControlName="id"
|
||||
(selectionChange)="show($event)"
|
||||
>
|
||||
<mat-option *ngFor="let s of list" [value]="s.id">
|
||||
{{ s.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<mat-form-field>
|
||||
<mat-label>Text</mat-label>
|
||||
<textarea
|
||||
matInput
|
||||
matAutosizeMinRows="5"
|
||||
placeholder="Text"
|
||||
formControlName="text"
|
||||
></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-divider></mat-divider>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
24
bookie/src/app/header-footer/header-footer.component.spec.ts
Normal file
24
bookie/src/app/header-footer/header-footer.component.spec.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HeaderFooterComponent } from './header-footer.component';
|
||||
|
||||
describe('HeaderFooterComponent', () => {
|
||||
let component: HeaderFooterComponent;
|
||||
let fixture: ComponentFixture<HeaderFooterComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [HeaderFooterComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(HeaderFooterComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
80
bookie/src/app/header-footer/header-footer.component.ts
Normal file
80
bookie/src/app/header-footer/header-footer.component.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
|
||||
import { HeaderFooter } from './header-footer';
|
||||
import { HeaderFooterService } from './header-footer.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-section-printer',
|
||||
templateUrl: './header-footer.component.html',
|
||||
styleUrls: ['./header-footer.component.css'],
|
||||
})
|
||||
export class HeaderFooterComponent implements OnInit {
|
||||
@ViewChild('section', { static: true }) sectionElement: ElementRef;
|
||||
form: FormGroup;
|
||||
list: HeaderFooter[];
|
||||
id: string;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private ser: HeaderFooterService,
|
||||
) {
|
||||
this.createForm();
|
||||
route.params.pipe(map((p) => p.id)).subscribe((x) => {
|
||||
this.id = x;
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
id: '',
|
||||
text: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: HeaderFooter[] }) => {
|
||||
this.showItem(data.list);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(list: HeaderFooter[]) {
|
||||
this.list = list;
|
||||
this.form.setValue({
|
||||
id: this.id,
|
||||
text: this.list.find((v) => v.id === this.id).text,
|
||||
});
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.save(this.getItem()).subscribe(
|
||||
(result: HeaderFooter[]) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.showItem(result);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getItem(): HeaderFooter {
|
||||
const formModel = this.form.value;
|
||||
const item = this.list.find((v) => v.id === this.id);
|
||||
item.text = formModel.text;
|
||||
return item;
|
||||
}
|
||||
|
||||
show(val: any) {
|
||||
this.router.navigate(['/header-footer', val.value]);
|
||||
}
|
||||
}
|
13
bookie/src/app/header-footer/header-footer.module.spec.ts
Normal file
13
bookie/src/app/header-footer/header-footer.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { HeaderFooterModule } from './header-footer.module';
|
||||
|
||||
describe('HeaderFooterModule', () => {
|
||||
let headerFooterModule: HeaderFooterModule;
|
||||
|
||||
beforeEach(() => {
|
||||
headerFooterModule = new HeaderFooterModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(headerFooterModule).toBeTruthy();
|
||||
});
|
||||
});
|
41
bookie/src/app/header-footer/header-footer.module.ts
Normal file
41
bookie/src/app/header-footer/header-footer.module.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { HeaderFooterRoutingModule } from './header-footer-routing.module';
|
||||
import { HeaderFooterComponent } from './header-footer.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDividerModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
HeaderFooterRoutingModule,
|
||||
],
|
||||
declarations: [HeaderFooterComponent],
|
||||
})
|
||||
export class HeaderFooterModule {}
|
15
bookie/src/app/header-footer/header-footer.service.spec.ts
Normal file
15
bookie/src/app/header-footer/header-footer.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HeaderFooterService } from './header-footer.service';
|
||||
|
||||
describe('HeaderFooterService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [HeaderFooterService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([HeaderFooterService], (service: HeaderFooterService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
35
bookie/src/app/header-footer/header-footer.service.ts
Normal file
35
bookie/src/app/header-footer/header-footer.service.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
import { HeaderFooter } from './header-footer';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/header-footer';
|
||||
const serviceName = 'HeaderFooterService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class HeaderFooterService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
list(): Observable<HeaderFooter[]> {
|
||||
return <Observable<HeaderFooter[]>>(
|
||||
this.http.get<HeaderFooter[]>(url).pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(item: HeaderFooter): Observable<HeaderFooter[]> {
|
||||
return <Observable<HeaderFooter[]>>(
|
||||
this.http
|
||||
.post<HeaderFooter[]>(url, item, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
}
|
5
bookie/src/app/header-footer/header-footer.ts
Normal file
5
bookie/src/app/header-footer/header-footer.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export class HeaderFooter {
|
||||
id: string;
|
||||
name: string;
|
||||
text?: string;
|
||||
}
|
@ -197,6 +197,15 @@
|
||||
>
|
||||
<h3 class="item-name">Users</h3>
|
||||
</mat-card>
|
||||
<mat-card
|
||||
fxLayout="column"
|
||||
class="square-button"
|
||||
matRipple
|
||||
*ngIf="auth.user && auth.user.perms.indexOf('products') !== -1"
|
||||
[routerLink]="['/', 'header-footer']"
|
||||
>
|
||||
<h3 class="item-name">Header / Footer</h3>
|
||||
</mat-card>
|
||||
</div>
|
||||
<footer class="footer">
|
||||
<p>Backend: v{{ auth.user?.ver }} / Frontend: v{{ version }} on {{ auth.device.name }}</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user