Skip to content
This repository was archived by the owner on Nov 19, 2021. It is now read-only.

Commit 87ae8c8

Browse files
committed
services created
1 parent 4b341c4 commit 87ae8c8

27 files changed

+275
-24
lines changed

src/app/app-routing.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CartService } from './cart.service';
12
import { componentFactoryName } from '@angular/compiler';
23
import { NgModule } from '@angular/core';
34
import { Routes, RouterModule } from '@angular/router';
@@ -13,7 +14,7 @@ const routes: Routes = [
1314
},
1415

1516
{
16-
path: '',
17+
path: 'image-view',
1718
component: ImageViewComponent,
1819
},
1920
];

src/app/app.module.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CartService } from './cart.service';
2+
import { DashboardComponent } from './dashboard/dashboard.component';
13
import { NgModule, Type } from '@angular/core';
24
import { BrowserModule, Title } from '@angular/platform-browser';
35
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@@ -13,6 +15,7 @@ import { routedComponents, AppRoutingModule } from './app-routing.module';
1315

1416
import { SharedModule } from './shared/shared.module';
1517
import { ImageViewComponent } from './image-view/image-view.component';
18+
import { CartComponent } from './cart/cart.component';
1619

1720
const httpInterceptorProviders: Type<any>[] = [
1821
RequestInterceptor,
@@ -23,6 +26,8 @@ const httpInterceptorProviders: Type<any>[] = [
2326
AppComponent,
2427
routedComponents,
2528
ImageViewComponent,
29+
CartComponent,
30+
DashboardComponent,
2631
], // directives, components, and pipes owned by this NgModule
2732
imports: [
2833
AppRoutingModule,
@@ -39,6 +44,7 @@ const httpInterceptorProviders: Type<any>[] = [
3944
], // modules needed to run this module
4045
providers: [
4146
httpInterceptorProviders,
47+
CartService,
4248
], // additional providers needed for this module
4349
entryComponents: [ ],
4450
bootstrap: [ AppComponent ],

src/app/cart.service.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { CartService } from './cart.service';
4+
5+
describe('CartService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [CartService]
9+
});
10+
});
11+
12+
it('should be created', inject([CartService], (service: CartService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});

src/app/cart.service.ts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { Injectable } from '@angular/core';
2+
import { MdSnackBar } from '@angular/material';
3+
4+
@Injectable()
5+
export class CartService {
6+
7+
itemArray: string[] = [];
8+
9+
imageArray: any[] = [{
10+
11+
columnSize: '40',
12+
column: [{
13+
url: '../../assets/images/alex-lambley-205711-min.jpg',
14+
isclicked: false,
15+
}, {
16+
url: '../../assets/images/norman-toth-177290-min.jpg',
17+
isclicked: false,
18+
}, {
19+
url: '../../assets/images/kaci-baum-108756-min.jpg',
20+
isclicked: false,
21+
}, {
22+
url: '../../assets/images/ariel-lustre-232891-min.jpg',
23+
isclicked: false,
24+
}],
25+
}, {
26+
columnSize: '25',
27+
column: [{
28+
url: '../../assets/images/pete-bellis-189599-min.jpg',
29+
isclicked: false,
30+
}, {
31+
url: '../../assets/images/remy_loz-188297-min.jpg',
32+
isclicked: false,
33+
}, {
34+
url: '../../assets/images/brooke-cagle-195860-min.jpg',
35+
isclicked: false,
36+
}, {
37+
url: '../../assets/images/freestocks-org-195640-min.jpg',
38+
isclicked: false,
39+
}],
40+
}, {
41+
columnSize: '25',
42+
column: [{
43+
url: '../../assets/images/pete-bellis-189613-min.jpg',
44+
isclicked: false,
45+
}, {
46+
url: '../../assets/images/pete-bellis-191833-min.jpg',
47+
isclicked: false,
48+
},
49+
],
50+
}, {
51+
columnSize: '25',
52+
column: [{
53+
url: '../../assets/images/valerie-elash-275588-min.jpg',
54+
isclicked: false,
55+
},
56+
{
57+
url: '../../assets/images/jason-blackeye-221058-min.jpg',
58+
isclicked: false,
59+
}],
60+
}];
61+
62+
constructor(public snackBar: MdSnackBar) { }
63+
64+
public clickedAddToCart(imageUrl: any): void {
65+
const items: string[] = this.itemArray;
66+
const msg: string = 'Added to cart';
67+
const action: string = 'Ok';
68+
const color: string = 'green';
69+
const duration: number = 2000;
70+
this.snackBar.open(msg, action, {
71+
duration: duration,
72+
extraClasses: ['bgc-' + color + '-600'],
73+
});
74+
items.push(imageUrl);
75+
}
76+
public getNitems(): number {
77+
return this.itemArray.length;
78+
}
79+
}

src/app/cart/cart.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
cart works!
3+
</p>

src/app/cart/cart.component.scss

Whitespace-only changes.

src/app/cart/cart.component.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { CartComponent } from './cart.component';
4+
5+
describe('CartComponent', () => {
6+
let component: CartComponent;
7+
let fixture: ComponentFixture<CartComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ CartComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(CartComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should be created', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

src/app/cart/cart.component.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-cart',
5+
templateUrl: './cart.component.html',
6+
styleUrls: ['./cart.component.scss']
7+
})
8+
export class CartComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

src/app/dashboard/dashboard.component.html

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
<td-layout-nav logo="assets:covalent">
2+
23
<div td-toolbar-content layout="row" layout-align="center center" flex>
34
<span>Quickstart</span>
45
<span flex></span>
5-
<button md-icon-button mdTooltip="Cart"><md-icon>shopping_cart</md-icon></button>
6+
<button md-icon-button [mdMenuTriggerFor]="cart" mdTooltip="Cart" (click)="clickedCart()">
7+
<td-notification-count positionX="after" positionY="bottom"color="accent" [notifications]="notifications()">
8+
<md-icon>shopping_cart</md-icon>
9+
</td-notification-count>
10+
</button>
11+
<md-menu #cart="mdMenu">
12+
<td-menu>
13+
<div td-menu-header class="md-subhead">Products in your cart</div>
14+
<md-nav-list dense>
15+
<a md-list-item *ngFor="let item of itemArray">
16+
<md-icon md-list-avatar>today</md-icon>
17+
<h4 md-line><span class="text-wrap">item</span></h4>
18+
</a>
19+
<md-divider *ngIf="!last"></md-divider>
20+
</md-nav-list>
21+
<button md-button color="accent" td-menu-footer>
22+
See All products
23+
</button>
24+
</td-menu>
25+
</md-menu>
626
<a md-icon-button mdTooltip="Docs" href="https://teradata.github.io/covalent/" target="_blank">
727
<md-icon>chrome_reader_mode</md-icon>
828
</a>
929
<a md-icon-button mdTooltip="Github" href="https://github.com/teradata/covalent" target="_blank">
1030
<md-icon svgIcon="assets:github"></md-icon>
1131
</a>
1232
</div>
33+
34+
1335
<div layout-gt-sm="row" tdMediaToggle="gt-xs" [mediaClasses]="['push-sm']">
1436
<div flex-gt-sm="column.columnSize" *ngFor="let column of imageArray">
1537
<md-card *ngFor="let image of column.column">
@@ -18,7 +40,8 @@
1840
<div layout="row" class="tc-grey-600">
1941
<button md-icon-button mdTooltip="Like"><md-icon>favorite</md-icon></button>
2042
<button md-icon-button mdTooltip="Comment"><md-icon>comment</md-icon></button>
21-
<button md-icon-button mdTooltip="Add to cart"><md-icon>add_shopping_cart</md-icon></button>
43+
<button md-icon-button mdTooltip="Add to cart" (click)="clickedAddToCart(image.url)">
44+
<md-icon>add_shopping_cart</md-icon></button>
2245
<span flex></span>
2346
<button md-icon-button mdTooltip="Share"><md-icon>share</md-icon></button>
2447
</div>
+36-16
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,93 @@
1+
import { TdDialogService } from '@covalent/core/dialogs/services/dialog.service';
12
import { Router } from '@angular/router';
23
import { Component, OnInit } from '@angular/core';
34
import { Title } from '@angular/platform-browser';
4-
import { TdLoadingService, TdDigitsPipe } from '@covalent/core';
5+
import { TdLoadingService, TdDigitsPipe, CovalentNotificationsModule } from '@covalent/core';
6+
import { MdSnackBar } from '@angular/material';
7+
8+
import { CartService } from '../cart.service';
59

610
@Component({
711
selector: 'qs-dashboard',
812
templateUrl: './dashboard.component.html',
9-
styleUrls: ['./dashboard.component.scss'],
13+
styleUrls: ['./dashboard.component.scss']
14+
// providers: [CartService],
1015
})
1116
export class DashboardComponent implements OnInit {
1217
imageArray: any[] = [{
18+
1319
columnSize: '40',
1420
column: [{
15-
url: '../../assets/images/alex-lambley-205711.jpg',
21+
url: '../../assets/images/alex-lambley-205711-min.jpg',
1622
isclicked: false,
1723
}, {
18-
url: '../../assets/images/norman-toth-177290.jpg',
24+
url: '../../assets/images/norman-toth-177290-min.jpg',
1925
isclicked: false,
2026
}, {
21-
url: '../../assets/images/kaci-baum-108756.jpg',
27+
url: '../../assets/images/kaci-baum-108756-min.jpg',
2228
isclicked: false,
2329
}, {
24-
url: '../../assets/images/ariel-lustre-232891.jpg',
30+
url: '../../assets/images/ariel-lustre-232891-min.jpg',
2531
isclicked: false,
2632
}],
2733
}, {
2834
columnSize: '25',
2935
column: [{
30-
url: '../../assets/images/pete-bellis-189599.jpg',
36+
url: '../../assets/images/pete-bellis-189599-min.jpg',
3137
isclicked: false,
3238
}, {
33-
url: '../../assets/images/remy_loz-188297.jpg',
39+
url: '../../assets/images/remy_loz-188297-min.jpg',
3440
isclicked: false,
3541
}, {
36-
url: '../../assets/images/brooke-cagle-195860.jpg',
42+
url: '../../assets/images/brooke-cagle-195860-min.jpg',
3743
isclicked: false,
3844
}, {
39-
url: '../../assets/images/freestocks-org-195640.jpg',
45+
url: '../../assets/images/freestocks-org-195640-min.jpg',
4046
isclicked: false,
4147
}],
4248
}, {
4349
columnSize: '25',
4450
column: [{
45-
url: '../../assets/images/pete-bellis-189613.jpg',
51+
url: '../../assets/images/pete-bellis-189613-min.jpg',
4652
isclicked: false,
4753
}, {
48-
url: '../../assets/images/pete-bellis-191833.jpg',
54+
url: '../../assets/images/pete-bellis-191833-min.jpg',
4955
isclicked: false,
5056
},
5157
],
5258
}, {
5359
columnSize: '25',
5460
column: [{
55-
url: '../../assets/images/valerie-elash-275588.jpg',
61+
url: '../../assets/images/valerie-elash-275588-min.jpg',
5662
isclicked: false,
5763
},
5864
{
59-
url: '../../assets/images/jason-blackeye-221058.jpg',
65+
url: '../../assets/images/jason-blackeye-221058-min.jpg',
6066
isclicked: false,
6167
}],
6268
}];
6369

64-
constructor(private _titleService: Title, private router: Router) { }
70+
constructor(
71+
private _titleService: Title,
72+
private router: Router,
73+
private dialogService: TdDialogService,
74+
public snackBar: MdSnackBar,
75+
private cartService: CartService) { }
6576

6677
ngOnInit(): void {
6778
this._titleService.setTitle('Covalent Quickstart');
6879
}
6980

7081
clickedImage(imageUrl: any): void {
71-
this.router.navigate(['/image-view']);
82+
this.router.navigate(['/image-view', { url: imageUrl }]);
83+
84+
}
85+
clickedAddToCart(imageUrl: any): void {
86+
const img: string = imageUrl;
87+
this.cartService.clickedAddToCart(img);
88+
}
89+
notifications(): number {
90+
const nItems: number = this.cartService.getNitems();
91+
return nItems;
7292
}
7393
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
<div class="big-img">
2-
<img src="../../assets/images/alex-lambley-205711.jpg" (click)="clickedImage()">
1+
<div>
2+
<div class="header-icons">
3+
<button class="buttons" md-icon-button mdTooltip="Close">
4+
<md-icon class="close-icon" (click)="clickedImage()">close
5+
</md-icon>
6+
</button>
7+
</div>
8+
<img class="big-img" src={{imageUrl}}>
39
</div>

0 commit comments

Comments
 (0)