Implement settings dialog
This commit is contained in:
parent
251fa5d327
commit
33326febaf
17 changed files with 125 additions and 126 deletions
12
angular.json
12
angular.json
|
@ -6,7 +6,7 @@
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"newProjectRoot": "projects",
|
"newProjectRoot": "projects",
|
||||||
"projects": {
|
"projects": {
|
||||||
"sell4zec": {
|
"zgo": {
|
||||||
"projectType": "application",
|
"projectType": "application",
|
||||||
"schematics": {
|
"schematics": {
|
||||||
"@schematics/angular:application": {
|
"@schematics/angular:application": {
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:browser",
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/sell4zec",
|
"outputPath": "dist/zgo",
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"main": "src/main.ts",
|
||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
|
@ -71,10 +71,10 @@
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"browserTarget": "sell4zec:build:production"
|
"browserTarget": "zgo:build:production"
|
||||||
},
|
},
|
||||||
"development": {
|
"development": {
|
||||||
"browserTarget": "sell4zec:build:development"
|
"browserTarget": "zgo:build:development"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultConfiguration": "development"
|
"defaultConfiguration": "development"
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
"extract-i18n": {
|
"extract-i18n": {
|
||||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "sell4zec:build"
|
"browserTarget": "zgo:build"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
|
@ -106,5 +106,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultProject": "sell4zec"
|
"defaultProject": "zgo"
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,14 +169,18 @@ app.post('/api/addowner', (req, res, next) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/addownername', (req, res, next) => {
|
app.post('/api/updateowner', (req, res, next) => {
|
||||||
console.log('Post: /api/addownername');
|
console.log('Post: /api/updateowner');
|
||||||
const owner = ownermodel.findOne({address: req.body.address});
|
ownermodel.findByIdAndUpdate(req.body.owner._id, req.body.owner,
|
||||||
|
function(err, docs) {
|
||||||
owner.name = req.body.name;
|
if (err) {
|
||||||
owner.save();
|
console.log(err);
|
||||||
|
} else {
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
message: 'Ownername added successfully'
|
message: 'Owner updated',
|
||||||
|
owner: docs
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ module.exports = function (config) {
|
||||||
suppressAll: true // removes the duplicated traces
|
suppressAll: true // removes the duplicated traces
|
||||||
},
|
},
|
||||||
coverageReporter: {
|
coverageReporter: {
|
||||||
dir: require('path').join(__dirname, './coverage/sell4zec'),
|
dir: require('path').join(__dirname, './coverage/zgo'),
|
||||||
subdir: '.',
|
subdir: '.',
|
||||||
reporters: [
|
reporters: [
|
||||||
{ type: 'html' },
|
{ type: 'html' },
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "sell4zec",
|
"name": "zgo",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { ItemAddComponent} from './items/item-add/item-add.component';
|
||||||
import { OrderComponent } from './order/order.component';
|
import { OrderComponent } from './order/order.component';
|
||||||
import { CancelComponent } from './cancel/cancel.component';
|
import { CancelComponent } from './cancel/cancel.component';
|
||||||
import { CheckoutComponent } from './checkout/checkout.component';
|
import { CheckoutComponent } from './checkout/checkout.component';
|
||||||
|
import { SettingsComponent } from './settings/settings.component';
|
||||||
//import { NameDialogComponent } from './namedialog/namedialog.component';
|
//import { NameDialogComponent } from './namedialog/namedialog.component';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
|
@ -37,7 +38,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
ItemDeleteComponent,
|
ItemDeleteComponent,
|
||||||
ItemAddComponent,
|
ItemAddComponent,
|
||||||
CancelComponent,
|
CancelComponent,
|
||||||
CheckoutComponent
|
CheckoutComponent,
|
||||||
|
SettingsComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -59,6 +61,13 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
entryComponents: [ItemCreateComponent, ItemDeleteComponent, ItemAddComponent, CancelComponent, CheckoutComponent]
|
entryComponents: [
|
||||||
|
ItemCreateComponent,
|
||||||
|
ItemDeleteComponent,
|
||||||
|
ItemAddComponent,
|
||||||
|
CancelComponent,
|
||||||
|
CheckoutComponent,
|
||||||
|
SettingsComponent
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
* {
|
.text {
|
||||||
font-family: 'Roboto Mono', monospace;
|
font-family: 'Roboto-Mono', monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
a{
|
a{
|
||||||
|
@ -21,3 +21,6 @@ ul{
|
||||||
font-size: 9px;
|
font-size: 9px;
|
||||||
line-height: 0.8;
|
line-height: 0.8;
|
||||||
}
|
}
|
||||||
|
.icon {
|
||||||
|
font-family: "Material Icons";
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<mat-toolbar color="primary">
|
<mat-toolbar color="primary">
|
||||||
<span>
|
<span align="center">
|
||||||
<a routerLink = "/">
|
<a routerLink = "/" class="text">
|
||||||
Z Go!
|
Z Go!
|
||||||
</a>
|
</a>
|
||||||
<p class="mini">Last block seen: {{heightUpdate | async}}</p>
|
<p class="mini text">Last block seen: {{heightUpdate | async}}</p>
|
||||||
</span>
|
</span>
|
||||||
<span class="spacer"></span>
|
<span class="spacer"></span>
|
||||||
<span align="center">
|
<span align="center">
|
||||||
<div>{{ shortenZaddr((ownerUpdate | async)!.address) }}</div>
|
<button mat-raised-button class="text" (click)="openSettings()">
|
||||||
|
{{ shortenZaddr((ownerUpdate | async)!.address) }} <mat-icon class="icon">manage_accounts</mat-icon>
|
||||||
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import {Component, OnInit, OnDestroy} from '@angular/core';
|
import {Component, OnInit, OnDestroy} from '@angular/core';
|
||||||
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
||||||
import {FullnodeService} from '../fullnode.service';
|
import {FullnodeService} from '../fullnode.service';
|
||||||
import { UserService } from '../user.service';
|
import { UserService } from '../user.service';
|
||||||
import {Subscription, Observable} from 'rxjs';
|
import {Subscription, Observable} from 'rxjs';
|
||||||
|
import { SettingsComponent } from '../settings/settings.component';
|
||||||
|
|
||||||
import {Owner} from '../owner.model';
|
import {Owner} from '../owner.model';
|
||||||
|
|
||||||
|
@ -22,11 +24,15 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public fullnodeService: FullnodeService,
|
public fullnodeService: FullnodeService,
|
||||||
public userService: UserService
|
public userService: UserService,
|
||||||
|
private dialog: MatDialog
|
||||||
){
|
){
|
||||||
this.heightUpdate = fullnodeService.heightUpdate;
|
this.heightUpdate = fullnodeService.heightUpdate;
|
||||||
this.uZaddrUpdate = userService.uZaddrUpdate;
|
this.uZaddrUpdate = userService.uZaddrUpdate;
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
|
this.ownerUpdate.subscribe((owner) => {
|
||||||
|
this.owner = owner;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,4 +49,21 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
||||||
return addr.substring(0,5).concat('...').concat(addr.substring(last, end));
|
return addr.substring(0,5).concat('...').concat(addr.substring(last, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openSettings() {
|
||||||
|
|
||||||
|
const dialogConfig = new MatDialogConfig();
|
||||||
|
|
||||||
|
dialogConfig.disableClose = true;
|
||||||
|
dialogConfig.autoFocus = true;
|
||||||
|
dialogConfig.data = this.owner;
|
||||||
|
|
||||||
|
const dialogRef = this.dialog.open(SettingsComponent, dialogConfig);
|
||||||
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
|
if (val != null) {
|
||||||
|
console.log('Saving settings');
|
||||||
|
this.userService.updateOwner(val);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
<!-- TODO: get this dialog working right-->
|
|
||||||
<h2 mat-dialog-title>Set the name of your business</h2>
|
|
||||||
<main>
|
|
||||||
<form (submit)="save(nameForm)" #nameForm="ngForm">
|
|
||||||
<mat-dialog-content>
|
|
||||||
<mat-form-field>
|
|
||||||
<input matInput type="text" name="bizname" placeholder="Bubba's Bakery" ngModel required #bizname="ngModel">
|
|
||||||
<mat-error *ngIf="bizname.invalid">This field is required</mat-error>
|
|
||||||
</mat-form-field>
|
|
||||||
</mat-dialog-content>
|
|
||||||
|
|
||||||
<mat-dialog-actions>
|
|
||||||
<button class="mat-raised-button" (click)="close()">Close</button>
|
|
||||||
<button class="mat-raised-button mat-primary" type="submit">Save</button>
|
|
||||||
</mat-dialog-actions>
|
|
||||||
</form>
|
|
||||||
</main>
|
|
|
@ -1,32 +0,0 @@
|
||||||
import { Inject, Component, OnInit, OnDestroy } from '@angular/core';
|
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
||||||
import { NgForm } from '@angular/forms';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'name-dialog',
|
|
||||||
templateUrl: './namedialog.component.html'
|
|
||||||
})
|
|
||||||
|
|
||||||
export class NameDialogComponent implements OnInit{
|
|
||||||
bizname: string = '';
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private dialogRef: MatDialogRef<NameDialogComponent>
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
save(form: NgForm) {
|
|
||||||
if (form.invalid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.dialogRef.close(form.value.bizname);
|
|
||||||
//console.log(`Saving name ${form.value.bizname}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
this.dialogRef.close();
|
|
||||||
}
|
|
||||||
}
|
|
0
src/app/settings/settings.component.css
Normal file
0
src/app/settings/settings.component.css
Normal file
12
src/app/settings/settings.component.html
Normal file
12
src/app/settings/settings.component.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<h2 mat-dialog-title class="text">Settings</h2>
|
||||||
|
|
||||||
|
<mat-dialog-content [formGroup]="settingsForm">
|
||||||
|
<mat-form-field>
|
||||||
|
<input matInput placeholder="Name" formControlName="name">
|
||||||
|
</mat-form-field>
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
<mat-dialog-actions>
|
||||||
|
<button mat-raised-button class="text" (click)="close()">Cancel</button>
|
||||||
|
<button mat-raised-button class="text" color="primary" (click)="save()">Save</button>
|
||||||
|
</mat-dialog-actions>
|
40
src/app/settings/settings.component.ts
Normal file
40
src/app/settings/settings.component.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||||
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||||
|
import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms';
|
||||||
|
import {User} from '../user.model';
|
||||||
|
import {Owner} from '../owner.model';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-settings',
|
||||||
|
templateUrl: './settings.component.html',
|
||||||
|
styleUrls: ['/settings.component.css']
|
||||||
|
})
|
||||||
|
|
||||||
|
export class SettingsComponent implements OnInit {
|
||||||
|
|
||||||
|
settingsForm: FormGroup;
|
||||||
|
owner: Owner;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private fb: FormBuilder,
|
||||||
|
private dialogRef: MatDialogRef<SettingsComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: Owner
|
||||||
|
) {
|
||||||
|
this.settingsForm = fb.group({
|
||||||
|
name: [data.name, Validators.required]
|
||||||
|
});
|
||||||
|
this.owner = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
this.owner.name = this.settingsForm.value.name;
|
||||||
|
this.dialogRef.close(this.owner);
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,10 +82,12 @@ export class UserService{
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
|
|
||||||
addOwnerName(address: string, name: string) {
|
updateOwner(owner: Owner) {
|
||||||
this.http.post<{message: string}>('http://localhost:3000/api/addownername', {address, name}).
|
this.http.post<{message: string, owner: Owner}>('http://localhost:3000/api/updateowner', {owner: owner}).
|
||||||
subscribe((responseData) => {
|
subscribe((responseData) => {
|
||||||
console.log(responseData.message);
|
console.log(responseData.message);
|
||||||
|
//this.dataStore.owner = responseData.owner;
|
||||||
|
//this._ownerUpdated.next(Object.assign({},this.dataStore).owner);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,40 +116,9 @@ export class UserService{
|
||||||
return this.uZaddr === this.oZaddr;
|
return this.uZaddr === this.oZaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//getUser(session: string) {
|
|
||||||
//const params = new HttpParams().append('session', session);
|
|
||||||
//console.log(`US: Searching for session ${session} `);
|
|
||||||
//this.http.get<{message: string, user: any}>('http://localhost:3000/api/getuser', { headers:{}, params: params, observe: 'response'}).
|
|
||||||
//subscribe((UserDataResponse) => {
|
|
||||||
//console.log(UserDataResponse.status);
|
|
||||||
//if (UserDataResponse.status == 200){
|
|
||||||
//this.uZaddr = UserDataResponse.body!.user[0].address;
|
|
||||||
//console.log(`US: Found user, returning zaddr ${this.uZaddr}`);
|
|
||||||
//this._uZaddrUpdated.next(this.uZaddr);
|
|
||||||
//} else {
|
|
||||||
//console.log('US: Did not find user');
|
|
||||||
//this._uZaddrUpdated.next('');
|
|
||||||
//}
|
|
||||||
//});
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
//getName() {
|
|
||||||
//if (this.session != null) {
|
|
||||||
//this.getUser(this.session);
|
|
||||||
//this._uZaddrUpdated.subscribe((addr: string) => {
|
|
||||||
//console.log(` US: ${addr}`);
|
|
||||||
//this.getOwner(addr);
|
|
||||||
//});
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
||||||
getNameUpdateListener() {
|
getNameUpdateListener() {
|
||||||
return this.uNameUpdated;
|
return this.uNameUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
//getZaddrUpdateListener() {
|
|
||||||
//return this.uZaddrUpdated;
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
* {
|
* {
|
||||||
font-family: 'Roboto Mono', monospace;
|
font-family: 'Roboto-Mono', monospace;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>{{message}}</h1>
|
<h1>{{(ownerUpdate | async)!.name}}</h1>
|
||||||
</div>
|
</div>
|
||||||
<table cellspacing="0" width="100%">
|
<table cellspacing="0" width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -44,20 +44,4 @@ export class ViewerComponent implements OnInit {
|
||||||
ngOnDestroy(){
|
ngOnDestroy(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//openDialog(address: string) {
|
|
||||||
//const dialogConfig = new MatDialogConfig();
|
|
||||||
|
|
||||||
//dialogConfig.autoFocus = true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*dialogConfig.data = {
|
|
||||||
* id: 1,
|
|
||||||
* title: 'Whee!'
|
|
||||||
*}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//const dialogRef = this.dialog.open(NameDialogComponent, dialogConfig);
|
|
||||||
|
|
||||||
//dialogRef.afterClosed().subscribe(name => this.userService.addOwnerName(address, name) );
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue