Skip to content

Commit

Permalink
güncelleme işlemi tamamlandı.
Browse files Browse the repository at this point in the history
  • Loading branch information
NisanurBulut committed Jul 27, 2020
1 parent 256bded commit 70a21fa
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
</div>
<div class="field is-narrow">
<button type="submit" [disabled]="!budgetForm.valid"
[ngClass]="{'is-primary':isNewItem,'is-success':!isNewItem}"
class="button is-primary">
Ekle
<p *ngIf="isNewItem">Ekle</p>
<p *ngIf="!isNewItem">Düzenle</p>
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ import { BudgetItem } from 'src/app/models/budget-item.model';
})
export class AddItemFormComponent implements OnInit {
constructor() { }
@Input() item: BudgetItem = new BudgetItem('', null);
@Input() item: BudgetItem;
// Parente haber verelim

isNewItem: boolean;
@Output() submitForm: EventEmitter<BudgetItem> = new EventEmitter();
ngOnInit() {
if (this.item) {
this.isNewItem = false;
} else {
this.isNewItem = true;
this.item = new BudgetItem('', null);
}
}
onSubmit(form: NgForm): void {
// bu değeri dinleyene formu gönderir
// parente haber verecek
this.submitForm.emit(form.value);
form.reset();
this.submitForm.emit(form.value);
form.reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { BudgetItem } from 'src/app/models/budget-item.model';
import { MatDialog } from '@angular/material/dialog';
import { EditItemModalComponent } from '../edit-item-modal/edit-item-modal.component';
import { IUpdateBudgetEvent } from 'src/app/shared/IUpdateBudgetEvent';


@Component({
Expand All @@ -13,6 +14,7 @@ export class BudgetItemListComponent implements OnInit {
@Input() budgetItems: BudgetItem[];
// tslint:disable-next-line: no-output-on-prefix
@Output() onDeleteBudgetItem: EventEmitter<BudgetItem> = new EventEmitter();
@Output() onUpdateBudgetItem: EventEmitter<IUpdateBudgetEvent> = new EventEmitter();
constructor(private dialog: MatDialog) { }

ngOnInit() {
Expand All @@ -32,7 +34,12 @@ export class BudgetItemListComponent implements OnInit {
dialogRef.afterClosed().subscribe(result => {
if (result) {
// güncelleme
this.budgetItems[this.budgetItems.indexOf(edBudgetItem)] = result;
// this.budgetItems[this.budgetItems.indexOf(edBudgetItem)] = result;

this.onUpdateBudgetItem.emit({
old: edBudgetItem,
new: result
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1>Bütçe Hesaplayıcı</h1>
</div>
<section class="total-budget-section">
<h2 class="red">1500</h2>
<h2 [ngClass]="{'red':totalBudget<0, 'green':totalBudget>=0}">{{this.totalBudget}}</h2>
</section>
<section class="add-item-section">
<div class="add-item-container">
Expand All @@ -19,4 +19,5 @@ <h2 class="red">1500</h2>
<hr style="margin-top: 0;">
<app-budget-item-list
[budgetItems]="budgetItems"
(onDeleteBudgetItem)="deleteItem($event)"></app-budget-item-list>
(onDeleteBudgetItem)="deleteItem($event)"
(onUpdateBudgetItem)="updateItem($event)"></app-budget-item-list>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { BudgetItem } from '../models/budget-item.model';
import { IUpdateBudgetEvent } from '../shared/IUpdateBudgetEvent';

@Component({
selector: 'app-budget-main',
Expand All @@ -9,15 +10,23 @@ import { BudgetItem } from '../models/budget-item.model';
export class BudgetMainComponent implements OnInit {

budgetItems: BudgetItem[] = new Array<BudgetItem>();
totalBudget = 0;
constructor() { }

ngOnInit() {
}
addItem(newItem: BudgetItem) {
this.budgetItems.push(newItem);
this.totalBudget += newItem.amount;
}
deleteItem(delItem: BudgetItem) {
const index = this.budgetItems.indexOf(delItem);
this.budgetItems.splice(index, 1);
this.totalBudget -= delItem.amount;
}
updateItem(updateEvent: IUpdateBudgetEvent) {
this.budgetItems[this.budgetItems.indexOf(updateEvent.old)] = updateEvent.new;
this.totalBudget -= updateEvent.old.amount;
this.totalBudget += updateEvent.new.amount;
}
}
6 changes: 6 additions & 0 deletions PratikForumClient/src/app/shared/IUpdateBudgetEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BudgetItem } from '../models/budget-item.model';

export interface IUpdateBudgetEvent {
old: BudgetItem;
new: BudgetItem;
}

0 comments on commit 70a21fa

Please sign in to comment.