-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<app-todo-list [tasks]="tasks"/> | ||
<!-- <app-todo-list [tasks]="tasks"/> --> | ||
<div class="m-4"> | ||
<app-calculator/> | ||
</div> | ||
|
||
<hr> | ||
<!-- <hr> | ||
<app-log-list/> | ||
<app-log-list/> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...pp/calculator/components/calculator-cell-operator/calculator-cell-operator.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<button | ||
class="h-full w-full" | ||
[class.bg-slate-100]="disabled" | ||
[class.hover:bg-slate-300]="!disabled" | ||
(click)="operatorClicked.emit(operator)" | ||
[disabled]="disabled" | ||
> | ||
{{operator}} | ||
</button> |
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
.../app/calculator/components/calculator-cell-operator/calculator-cell-operator.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { Operator } from '../../model/operator'; | ||
|
||
@Component({ | ||
selector: 'app-calculator-cell-operator', | ||
standalone: true, | ||
imports: [], | ||
templateUrl: './calculator-cell-operator.component.html', | ||
styleUrl: './calculator-cell-operator.component.scss' | ||
}) | ||
export class CalculatorCellOperatorComponent { | ||
|
||
@Input({ | ||
required: true | ||
}) | ||
operator?: Operator; | ||
|
||
@Input() | ||
disabled = false; | ||
|
||
@Output() | ||
operatorClicked = new EventEmitter<Operator>(); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...1022-angular/src/app/calculator/components/calculator-cell/calculator-cell.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<button | ||
class="h-full w-full hover:bg-slate-300" | ||
(click)="cellClicked.emit(value)" | ||
> | ||
{{value}} | ||
</button> |
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
...wa1022-angular/src/app/calculator/components/calculator-cell/calculator-cell.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-calculator-cell', | ||
standalone: true, | ||
imports: [], | ||
templateUrl: './calculator-cell.component.html', | ||
styleUrl: './calculator-cell.component.scss' | ||
}) | ||
export class CalculatorCellComponent { | ||
|
||
@Input({ | ||
required: true | ||
}) | ||
value?: number; | ||
|
||
@Output() | ||
cellClicked = new EventEmitter<number>(); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ages/dspwa1022-angular/src/app/calculator/components/calculator/calculator.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<div class="grid grid-cols-6 border w-72 text-center"> | ||
<div class="col-span-full border text-right pr-2"> | ||
{{lines[lines.length - 1]}} | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="1" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="2" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="3" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="4" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="5" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="6" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="7" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="8" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="9" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
|
||
<div class="col-span-1 border"> | ||
<app-calculator-cell-operator [operator]="operators.ADD" (operatorClicked)="appendOperator($event)"/> | ||
</div> | ||
<div class="col-span-1 border"> | ||
<app-calculator-cell-operator [operator]="operators.SUBTRACT" (operatorClicked)="appendOperator($event)"/> | ||
</div> | ||
|
||
<div class="col-span-2 border"> | ||
<app-calculator-cell [value]="0" (cellClicked)="appendDigit($event)"/> | ||
</div> | ||
|
||
<div class="col-span-2 border"> | ||
<app-calculator-cell-operator [operator]="operators.EQUAL" (operatorClicked)="appendOperator($event)" [disabled]="lines.length < 3 || lines[lines.length - 1] === 0"/> | ||
</div> | ||
</div> | ||
|
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
packages/dspwa1022-angular/src/app/calculator/components/calculator/calculator.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Component } from '@angular/core'; | ||
import { CalculatorCellComponent } from "../calculator-cell/calculator-cell.component"; | ||
import { CalculatorCellOperatorComponent } from "../calculator-cell-operator/calculator-cell-operator.component"; | ||
import { Operator } from '../../model/operator'; | ||
import { JsonPipe } from '@angular/common'; | ||
|
||
@Component({ | ||
selector: 'app-calculator', | ||
standalone: true, | ||
imports: [CalculatorCellComponent, CalculatorCellOperatorComponent], | ||
templateUrl: './calculator.component.html', | ||
styleUrl: './calculator.component.scss' | ||
}) | ||
export class CalculatorComponent { | ||
|
||
readonly operators = Operator; | ||
lines: (number | Operator)[] = [0]; | ||
|
||
appendDigit(digit: number) { | ||
this.lines[this.lines.length - 1] = (this.lines[this.lines.length - 1] as number) * 10 + digit; | ||
} | ||
|
||
appendOperator(operator: Operator) { | ||
if (operator === Operator.EQUAL) { | ||
const result = this.evaluateLines(); | ||
this.lines = [result]; | ||
} else { | ||
this.lines.push(operator); | ||
this.lines.push(0); | ||
} | ||
} | ||
|
||
private evaluateLines(): number { | ||
let result = 0; | ||
let nextOperator: Operator | undefined; | ||
|
||
for (const line of this.lines) { | ||
if (typeof line === 'number') { | ||
switch (nextOperator) { | ||
case Operator.ADD: | ||
result += line; | ||
break; | ||
case Operator.SUBTRACT: | ||
result -= line; | ||
break; | ||
case undefined: | ||
result = line; | ||
break; | ||
default: | ||
throw new Error(`Unexpected operator: ${nextOperator}`); | ||
} | ||
nextOperator = undefined; | ||
continue; | ||
} | ||
|
||
nextOperator = line; | ||
continue; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
packages/dspwa1022-angular/src/app/calculator/model/operator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Operator { | ||
ADD = '+', | ||
SUBTRACT = '-', | ||
EQUAL = '=', | ||
} |
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
Empty file.
2 changes: 1 addition & 1 deletion
2
...odo-list-item/todo-list-item.component.ts → ...odo-list-item/todo-list-item.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
4 changes: 2 additions & 2 deletions
4
...mponents/todo-list/todo-list.component.ts → ...mponents/todo-list/todo-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
layout: section | ||
--- | ||
|
||
<EmojiTitle title="Übung" emoji="👷"> | ||
Angular | ||
</EmojiTitle> | ||
|
||
<PageNumber/> | ||
|
||
<Footer | ||
text="💻 Frontend-Entwicklung" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
layout: default | ||
--- | ||
|
||
# Übung <SubHeading text="Angular"/> | ||
|
||
<div class="grid grid-cols-12 gap-6"> | ||
<div class="col-span-12"> | ||
|
||
- Installiert die aktuellen Dependencies mit `bun install` im Hauptverzeichnis | ||
- Installiert euch die [Angular CLI](https://angular.dev/tools/cli/setup-local#install-the-angular-cli) (Command Line Interface) | ||
- Wechselt ins [packages/dspwa1022-angular](https://github.com/volkmann-design-code/IU-DSPWA1022-Programmierung-von-Web-Anwendungen/tree/main/packages/dspwa1022-angular)-Verzeichnis und startet die Anwendung mit `bun start` (oder `ng serve`) | ||
- Öffnet die Anwendung unter [localhost:4200](http://localhost:4200/) | ||
- Aufgaben: | ||
- Erweitert den Rechner um Multiplikation und Division | ||
- Erweitert den Rechner um einen Button zum Zurücksetzen | ||
- Bonus: Ermöglicht die Eingabe von Komma-Zahlen | ||
|
||
</div> | ||
</div> | ||
|
||
<PageNumber/> |