Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,443 changes: 1,404 additions & 39 deletions ExpenseRecord/ClientApp/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ExpenseRecord/ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/jasmine": "~4.0.3",
"@types/jasminewd2": "~2.0.10",
"@types/node": "^18.0.0",
"eslint": "^8.52.0",
"jasmine-core": "~4.2.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.1",
Expand All @@ -49,6 +50,5 @@
},
"overrides": {
"autoprefixer": "10.4.5"
},
"optionalDependencies": {}
}
}
13 changes: 13 additions & 0 deletions ExpenseRecord/ClientApp/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { GreetingComponent } from './greeting/greeting.component';

const routes: Routes = [
{ path: '', component: GreetingComponent, pathMatch: 'full' }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
4 changes: 3 additions & 1 deletion ExpenseRecord/ClientApp/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<app-greeting></app-greeting>
<body>
<router-outlet></router-outlet>
</body>
13 changes: 9 additions & 4 deletions ExpenseRecord/ClientApp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CounterComponent } from './counter/counter.component';
import {GreetingComponent} from "./greeting/greeting.component";
import { ResponseListComponent } from './response-list/response-list.component';
import { ResponseComponent } from './response-list/response/response.component';
import { BottomPanelComponent } from './bottom-panel/bottom-panel.component';

@NgModule({
declarations: [
AppComponent,
CounterComponent,
GreetingComponent
GreetingComponent,
ResponseListComponent,
ResponseComponent,
BottomPanelComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
AppRoutingModule,
FormsModule,
],
providers: [],
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="create">
<input type="text" placeholder="Description" [(ngModel)]="expenseResponse.description" class="text">
<input type="text" placeholder="Type" [(ngModel)]="expenseResponse.type" />
<input type="number" placeholder="amount" [(ngModel)]="expenseResponse.amount" />
<button (click)="onClickAdd()">add</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { BottomPanelComponent } from './bottom-panel.component';

describe('BottomPanelComponent', () => {
let component: BottomPanelComponent;
let fixture: ComponentFixture<BottomPanelComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ BottomPanelComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(BottomPanelComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ExpenseResponse } from '../response-list/response-list.component';
import { DataService } from '../dataService';

@Component({
selector: 'app-bottom-panel',
templateUrl: './bottom-panel.component.html',
styleUrls: ['./bottom-panel.component.css']
})
export class BottomPanelComponent implements OnInit{
expenseResponse: ExpenseResponse = { id: "new", description: "", type: "", amount: 0, createdTime: Date.now() };
constructor(private dataService: DataService) { }

ngOnInit() {
this.clearInput();
}

onClickAdd() {
let subscription = this.dataService.addReponse(this.expenseResponse).subscribe(response => { this.clearInput(); location.reload(); });
setTimeout(() => {
subscription.unsubscribe();
}, 1000);
}

clearInput() {
this.expenseResponse = { id: "new", description: "", type: "", amount: 0, createdTime: Date.now() };
}
}

This file was deleted.

34 changes: 0 additions & 34 deletions ExpenseRecord/ClientApp/src/app/counter/counter.component.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions ExpenseRecord/ClientApp/src/app/counter/counter.component.ts

This file was deleted.

35 changes: 35 additions & 0 deletions ExpenseRecord/ClientApp/src/app/dataService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Inject, Injectable } from '@angular/core';
import { ExpenseResponse } from './response-list/response-list.component';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class DataService {
private url: string;
private http: HttpClient;

constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
this.http = http;
this.url = baseUrl + "/api/v1/ExpenseRecord";
}

responseList: ExpenseResponse[] = [];

getResponses(): Observable<ExpenseResponse[]> {
console.log(this.url);
let observable = this.http.get<ExpenseResponse[]>(this.url);
return observable;
}

addReponse(expenseResponse: ExpenseResponse) : Observable<ExpenseResponse>{
let observable = this.http.post<ExpenseResponse>(this.url, expenseResponse);
return observable;
}

deleteResponse(id: string): Observable<any>{
let observable = this.http.delete<any>(this.url + "/" + id);
return observable;
}
}
10 changes: 6 additions & 4 deletions ExpenseRecord/ClientApp/src/app/greeting/greeting.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<input type="text" [(ngModel)]="name">
<button (click)="greet()">greet</button>
<br>
<label> {{greeting}} </label>
<div>
<h1>Expense Records</h1>
<app-response-list></app-response-list>
<app-bottom-panel></app-bottom-panel>
</div>

10 changes: 0 additions & 10 deletions ExpenseRecord/ClientApp/src/app/greeting/greeting.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,4 @@ export class GreetingComponent implements OnInit {
ngOnInit(): void {
}

greet() {
this.callApi(this.name);
}

callApi(name: string) {
this.http.get<string>(this.baseUrl + 'greeting?name=' + name, {responseType: 'text' as 'json'})
.subscribe((result: string) => {
this.greeting = result;
}, (error: any) => console.error(error));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<table class="response-list" width="100%">
<tbody>
<tr *ngFor="let item of items">
<app-response [expenseResponse]="item" (deleteEvent)="deleteMethod($event)"></app-response>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ResponseListComponent } from './response-list.component';

describe('ResponseListComponent', () => {
let component: ResponseListComponent;
let fixture: ComponentFixture<ResponseListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ResponseListComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(ResponseListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Component, OnInit } from '@angular/core';
import { DataService } from 'src/app/dataService';

export interface ExpenseResponse {
id: string;
description: string;
type: string;
amount: number;
createdTime: number;
}

@Component({
selector: 'app-response-list',
templateUrl: './response-list.component.html',
styleUrls: ['./response-list.component.css']
})
export class ResponseListComponent implements OnInit {
constructor(private dataService: DataService) { }

items: ExpenseResponse[] = [];


ngOnInit(): void {
this.getResponseList();
}

getResponseList() {
let subscription = this.dataService.getResponses().subscribe(responses => this.items = responses.sort((a, b) => b.createdTime - a.createdTime)
);
setTimeout(() => {
subscription.unsubscribe();
}, 1000);
}

deleteMethod(id : string) {
let subscription = this.dataService.deleteResponse(id).subscribe(response => this.getResponseList());
setTimeout(() => {
subscription.unsubscribe();
}, 1000);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="item">
<td class="left">
<a [routerLink]="['/response/', expenseResponse.id]">
{{expenseResponse.description}}
</a>
, {{expenseResponse.type}}, {{expenseResponse.amount}}, {{expenseResponse.createdTime | date:"shortDate"}}
</td>
<td class="right">
<button (click)="onClickDelete()">delete</button>
</td>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ResponseComponent } from './response.component';

describe('ResponseComponent', () => {
let component: ResponseComponent;
let fixture: ComponentFixture<ResponseComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ResponseComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(ResponseComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { ExpenseResponse } from '../../response-list/response-list.component';

@Component({
selector: 'app-response',
templateUrl: './response.component.html',
styleUrls: ['./response.component.css']
})
export class ResponseComponent implements OnInit {
@Input() expenseResponse: ExpenseResponse = { id: "-1", description: "default", type: "default", amount: 0, createdTime: Date.now() };
@Output() deleteEvent = new EventEmitter<string>();

constructor() { }

ngOnInit(): void {
}

onClickDelete() {
this.deleteEvent.emit(this.expenseResponse.id);
}

}
Loading