Skip to content

Commit

Permalink
added possibility for admins to edit product from main page
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveRusin committed Oct 4, 2017
1 parent 20a4f9b commit 6542d34
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/admin-page/new-orders/order/order.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
</app-ordered-product>
</div>
<md-action-row>
<button md-button color="primary" (click)="accept()">Mark as accepted</button>
<button md-button color="primary" (click)="accept()">Mark as completed</button>
</md-action-row>
</md-expansion-panel>
4 changes: 1 addition & 3 deletions src/app/guards/admin.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { AngularFireAuth } from 'angularfire2/auth';

@Injectable()
export class AdminGuard implements CanActivate {
adminsArr = [
"PAUi0aWuH5T062teCexxtByBHTB3"
];


constructor(
private _router: Router,
Expand Down
1 change: 1 addition & 0 deletions src/app/homepage/homepage.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h2 md-subheader>Sorting by category</h2>
</div>
<div class = "rightcol wrapper">
<div class="oneObjet" *ngFor = "let product of prods | paginate: { itemsPerPage: 12, currentPage: p}">
<md-icon *ngIf="isAdmin" svgIcon="mode_edit" class="edit" (click)="onEdit(product)"></md-icon>
<div class="productImg">
<img src="{{ product.svg }}" alt="">
</div>
Expand Down
27 changes: 23 additions & 4 deletions src/app/homepage/homepage.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
box-sizing: border-box;
border: 1px solid #eee;

> * {
/* > * {
width: 100%;
}
} */

ul, li {
list-style-type: none;
Expand Down Expand Up @@ -101,6 +101,24 @@
margin-top: 100px;
color: #7b0041;
}

/deep/ .edit {
cursor: pointer;
position: absolute;
right: 10px;
top: 10px;
transition: ease all .2s;

&:hover{
svg {
path:first-child {
fill: $darkRead;
}
}
}


}
}

.leftcol {
Expand Down Expand Up @@ -157,9 +175,9 @@ md-divider {
align-content: flex-start;
width: 79%;

* {
/* * {
width: 100%;
}
} */

.productImg {
text-align: center;
Expand Down Expand Up @@ -223,6 +241,7 @@ md-divider {


.oneObjet {
position: relative;
display: flex;
flex-direction: column;
align-items: space-between;
Expand Down
78 changes: 63 additions & 15 deletions src/app/homepage/homepage.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy} from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core';
import { ProductsListService } from '../services/products-list.service';
import { PosterComponent } from './poster/poster.component';
import { SmoothScrollToDirective, SmoothScrollDirective } from "ng2-smooth-scroll";
Expand All @@ -16,6 +16,11 @@ import { CurrencyPipe } from '@angular/common';
import { Subject } from 'rxjs/Subject';
import { SafeHtml } from '@angular/platform-browser';
import { MdMenuModule } from '@angular/material';
import { MdIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
import { MdDialog } from '@angular/material';
import { EditProductComponent } from '../admin-page/remove-menu/remove-product/edit-product/edit-product.component';
import { AdminService } from '../services/admin.service';

@Component({
moduleId: module.id,
Expand All @@ -31,20 +36,45 @@ export class HomepageComponent implements OnInit {
@Input() filtered: Product[];
@Output() click = new EventEmitter();
productsCategory: any[] = PRODUCT_CATEGORY_FILTER;
procuctsType: any[] = PRODUCT_TYPE_FILTER;
procuctsType: any[] = PRODUCT_TYPE_FILTER;
public selected: string = '';
categories: FirebaseListObservable<any>;
templateTypes: FirebaseListObservable<any>;
@Input() product;
deleteButton: boolean;
startAt = new Subject()
endAt = new Subject()
endAt = new Subject();
isAdmin: boolean;
subscriptionToUserService: Subscription
subscriptionToAdminService: Subscription

constructor(private productListService: ProductsListService, private db: AngularFireDatabase, private designService: DesignService, private orderService: OrderService, public snackBar: MdSnackBar, private router: Router, private userService: UserService) {
constructor(
private productListService: ProductsListService,
private db: AngularFireDatabase,
private designService: DesignService,
private orderService: OrderService,
public snackBar: MdSnackBar,
private router: Router,
private userService: UserService,
private iconRegistry: MdIconRegistry,
private sanitizer: DomSanitizer,
public dialog: MdDialog,
private adminService: AdminService
) {
iconRegistry
.addSvgIcon('mode_edit', sanitizer.bypassSecurityTrustResourceUrl('../../assets/icons/ic_mode_edit_black_24px.svg'))
};

ngOnInit():void {
this.designService.getDesignCategory().subscribe(res => {this.categories = res});
ngOnInit(): void {
let that = this;
this.subscriptionToUserService = this.userService.getUserIdAsync().subscribe(user => {
this.subscriptionToAdminService = this.adminService.getAdmin(user.uid).subscribe(admin => {
if(admin.length > 0){
this.isAdmin = true;
}
})
})
this.designService.getDesignCategory().subscribe(res => { this.categories = res });
this.productListService.getTemplateTypes().subscribe(res => {
this.templateTypes = res;
});
Expand All @@ -53,24 +83,29 @@ export class HomepageComponent implements OnInit {
this.arrOfProds = this.prods;
});
//this.productListService.getProducts2(this.startAt, this.endAt).subscribe(items => this.prods = items);
};
};

ngOnDestroy(){
this.subscriptionToUserService.unsubscribe();
this.subscriptionToAdminService.unsubscribe()
}

sorting(propValue) {
this.productListService.selectProducts(propValue).subscribe(res=> {
sorting(propValue) {
this.productListService.selectProducts(propValue).subscribe(res => {
this.prods = res;
});
}

navChanged (child: string){
navChanged(child: string) {
this.selected = child
}
}

search(search) {
search(search) {
this.prods = this.arrOfProds;
this.prods = this.productListService.search(search, this.prods);
}
addToCart(product):void {

addToCart(product): void {
if (!product.size) {
let config = new MdSnackBarConfig();
config.extraClasses = ['success-snackbar'];
Expand All @@ -85,7 +120,20 @@ export class HomepageComponent implements OnInit {
}
}

setSize(size, product):void {
setSize(size, product): void {
product.size = size;
}

onEdit({ $key, name, category, owner, price, type }) {
let dialogRef = this.dialog.open(EditProductComponent, {
data: {
$key: $key,
name: name,
category: category,
owner: owner,
price: price,
type: type
}
});
}
}
6 changes: 5 additions & 1 deletion src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ export class UserService {
// return this.db.object('/users/' + userId + '/gallery');
// }

getUserId(){
getUserId(): string{
return this.afAuth.auth.currentUser.uid;
}

getUserIdAsync(){
return this.afAuth.authState
}

isUserLogIn() {
return this.afAuth.auth.currentUser;
}
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons/ic_mode_edit_black_24px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6542d34

Please sign in to comment.