Initial
This commit is contained in:
commit
28c0420354
39 changed files with 9664 additions and 0 deletions
17
.editorconfig
Normal file
17
.editorconfig
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
ij_typescript_use_double_quotes = false
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
42
.gitignore
vendored
Normal file
42
.gitignore
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
|
||||
|
||||
# Compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
/bazel-out
|
||||
|
||||
# Node
|
||||
/node_modules
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# IDEs and editors
|
||||
.idea/
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history/*
|
||||
|
||||
# Miscellaneous
|
||||
/.angular/cache
|
||||
.sass-cache/
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
testem.log
|
||||
/typings
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
4
.vscode/extensions.json
vendored
Normal file
4
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
|
||||
"recommendations": ["angular.ng-template"]
|
||||
}
|
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ng serve",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "npm: start",
|
||||
"url": "http://localhost:4200/"
|
||||
},
|
||||
{
|
||||
"name": "ng test",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "npm: test",
|
||||
"url": "http://localhost:9876/debug.html"
|
||||
}
|
||||
]
|
||||
}
|
42
.vscode/tasks.json
vendored
Normal file
42
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "start",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"owner": "typescript",
|
||||
"pattern": "$tsc",
|
||||
"background": {
|
||||
"activeOnStart": true,
|
||||
"beginsPattern": {
|
||||
"regexp": "(.*?)"
|
||||
},
|
||||
"endsPattern": {
|
||||
"regexp": "bundle generation complete"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "test",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"owner": "typescript",
|
||||
"pattern": "$tsc",
|
||||
"background": {
|
||||
"activeOnStart": true,
|
||||
"beginsPattern": {
|
||||
"regexp": "(.*?)"
|
||||
},
|
||||
"endsPattern": {
|
||||
"regexp": "bundle generation complete"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
59
README.md
Normal file
59
README.md
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Todo
|
||||
|
||||
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.0.1.
|
||||
|
||||
## Development server
|
||||
|
||||
To start a local development server, run:
|
||||
|
||||
```bash
|
||||
ng serve
|
||||
```
|
||||
|
||||
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
||||
|
||||
```bash
|
||||
ng generate component component-name
|
||||
```
|
||||
|
||||
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
||||
|
||||
```bash
|
||||
ng generate --help
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To build the project run:
|
||||
|
||||
```bash
|
||||
ng build
|
||||
```
|
||||
|
||||
This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
||||
|
||||
```bash
|
||||
ng test
|
||||
```
|
||||
|
||||
## Running end-to-end tests
|
||||
|
||||
For end-to-end (e2e) testing, run:
|
||||
|
||||
```bash
|
||||
ng e2e
|
||||
```
|
||||
|
||||
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
||||
|
||||
## Additional Resources
|
||||
|
||||
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
92
angular.json
Normal file
92
angular.json
Normal file
|
@ -0,0 +1,92 @@
|
|||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"todo": {
|
||||
"projectType": "application",
|
||||
"schematics": {},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular/build:application",
|
||||
"options": {
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": [
|
||||
"zone.js"
|
||||
],
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kB",
|
||||
"maximumError": "1MB"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "4kB",
|
||||
"maximumError": "8kB"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular/build:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "todo:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "todo:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular/build:extract-i18n"
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular/build:karma",
|
||||
"options": {
|
||||
"polyfills": [
|
||||
"zone.js",
|
||||
"zone.js/testing"
|
||||
],
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8921
package-lock.json
generated
Normal file
8921
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
36
package.json
Normal file
36
package.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "todo",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/common": "^20.0.0",
|
||||
"@angular/compiler": "^20.0.0",
|
||||
"@angular/core": "^20.0.0",
|
||||
"@angular/forms": "^20.0.0",
|
||||
"@angular/platform-browser": "^20.0.0",
|
||||
"@angular/router": "^20.0.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^20.0.1",
|
||||
"@angular/cli": "^20.0.1",
|
||||
"@angular/compiler-cli": "^20.0.0",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"jasmine-core": "~5.7.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"typescript": "~5.8.2"
|
||||
}
|
||||
}
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
12
src/app/app.config.ts
Normal file
12
src/app/app.config.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(routes)
|
||||
]
|
||||
};
|
0
src/app/app.css
Normal file
0
src/app/app.css
Normal file
1
src/app/app.html
Normal file
1
src/app/app.html
Normal file
|
@ -0,0 +1 @@
|
|||
<router-outlet></router-outlet>
|
15
src/app/app.routes.ts
Normal file
15
src/app/app.routes.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { Routes } from '@angular/router';
|
||||
import { TodoTable } from './todo-table/todo-table';
|
||||
import { Home } from './home/home';
|
||||
import { EditTodo } from './edit-todo/edit-todo';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: Home,
|
||||
},
|
||||
{
|
||||
path: 'edit/:id',
|
||||
component: EditTodo,
|
||||
},
|
||||
];
|
23
src/app/app.spec.ts
Normal file
23
src/app/app.spec.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
import { App } from './app';
|
||||
|
||||
describe('App', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [App],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, todo');
|
||||
});
|
||||
});
|
14
src/app/app.ts
Normal file
14
src/app/app.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { TodoTable } from './todo-table/todo-table';
|
||||
import { CreateTodo } from './create-todo/create-todo';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
imports: [RouterOutlet, TodoTable, CreateTodo],
|
||||
templateUrl: './app.html',
|
||||
styleUrl: './app.css',
|
||||
})
|
||||
export class App {
|
||||
protected title = 'todo';
|
||||
}
|
0
src/app/create-todo/create-todo.css
Normal file
0
src/app/create-todo/create-todo.css
Normal file
7
src/app/create-todo/create-todo.html
Normal file
7
src/app/create-todo/create-todo.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
<p>create-todo works!</p>
|
||||
<form [formGroup]="form" (submit)="submit()">
|
||||
<input type="number" formControlName="id" style="display: hidden" />
|
||||
<input type="text" formControlName="title" />
|
||||
<input type="date" formControlName="dueDate" />
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
23
src/app/create-todo/create-todo.spec.ts
Normal file
23
src/app/create-todo/create-todo.spec.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CreateTodo } from './create-todo';
|
||||
|
||||
describe('CreateTodo', () => {
|
||||
let component: CreateTodo;
|
||||
let fixture: ComponentFixture<CreateTodo>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CreateTodo]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CreateTodo);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
70
src/app/create-todo/create-todo.ts
Normal file
70
src/app/create-todo/create-todo.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { DatePipe } from '@angular/common';
|
||||
import { Component, Input, input, ResourceRef } from '@angular/core';
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-todo',
|
||||
imports: [ReactiveFormsModule],
|
||||
templateUrl: './create-todo.html',
|
||||
styleUrl: './create-todo.css',
|
||||
})
|
||||
export class CreateTodo {
|
||||
public form!: FormGroup;
|
||||
private datePipe = new DatePipe('en-US');
|
||||
@Input({ required: true }) tasks!: ResourceRef<any>;
|
||||
|
||||
submit() {
|
||||
if (this.form.valid) {
|
||||
if (this.form.value.id == -1) {
|
||||
this.createTask(this.form.value);
|
||||
} else {
|
||||
this.updateTask(this.form.value);
|
||||
}
|
||||
this.form.controls['id'].setValue(-1);
|
||||
}
|
||||
}
|
||||
|
||||
editTask(task: Task) {
|
||||
this.form.patchValue({ id: task.id });
|
||||
}
|
||||
|
||||
updateTask(task: Task) {
|
||||
fetch('http://localhost:2000/api/tasks/' + task.id, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(task),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
}).then(() => {
|
||||
this.tasks.reload();
|
||||
});
|
||||
}
|
||||
|
||||
createTask(task: Task) {
|
||||
fetch('http://localhost:2000/api/tasks', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(task),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
}).then(() => {
|
||||
this.tasks.reload();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.form = new FormGroup({
|
||||
id: new FormControl(-1),
|
||||
title: new FormControl('', Validators.required),
|
||||
dueDate: new FormControl(
|
||||
this.datePipe.transform(new Date(), 'yyyy-MM-dd'),
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
0
src/app/edit-todo/edit-todo.css
Normal file
0
src/app/edit-todo/edit-todo.css
Normal file
1
src/app/edit-todo/edit-todo.html
Normal file
1
src/app/edit-todo/edit-todo.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p>edit-todo works!</p>
|
23
src/app/edit-todo/edit-todo.spec.ts
Normal file
23
src/app/edit-todo/edit-todo.spec.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { EditTodo } from './edit-todo';
|
||||
|
||||
describe('EditTodo', () => {
|
||||
let component: EditTodo;
|
||||
let fixture: ComponentFixture<EditTodo>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [EditTodo]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(EditTodo);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
18
src/app/edit-todo/edit-todo.ts
Normal file
18
src/app/edit-todo/edit-todo.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Component, inject } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-edit-todo',
|
||||
imports: [],
|
||||
templateUrl: './edit-todo.html',
|
||||
styleUrl: './edit-todo.css',
|
||||
})
|
||||
export class EditTodo {
|
||||
private router = inject(ActivatedRoute);
|
||||
private task!: Task;
|
||||
|
||||
ngOnInit() {
|
||||
const id = this.router.snapshot.paramMap.get('id');
|
||||
fetch('http://localhost/api/tasks/');
|
||||
}
|
||||
}
|
0
src/app/home/home.css
Normal file
0
src/app/home/home.css
Normal file
2
src/app/home/home.html
Normal file
2
src/app/home/home.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<app-create-todo #form [tasks]="table.tasks"></app-create-todo>
|
||||
<app-todo-table #table [editTask]="form.editTask"></app-todo-table>
|
23
src/app/home/home.spec.ts
Normal file
23
src/app/home/home.spec.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { Home } from './home';
|
||||
|
||||
describe('Home', () => {
|
||||
let component: Home;
|
||||
let fixture: ComponentFixture<Home>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Home]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(Home);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
12
src/app/home/home.ts
Normal file
12
src/app/home/home.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { TodoTable } from '../todo-table/todo-table';
|
||||
import { CreateTodo } from '../create-todo/create-todo';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
imports: [RouterOutlet, TodoTable, CreateTodo],
|
||||
templateUrl: './home.html',
|
||||
styleUrl: './home.css',
|
||||
})
|
||||
export class Home {}
|
6
src/app/todo-table/task.ts
Normal file
6
src/app/todo-table/task.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
interface Task {
|
||||
id?: number;
|
||||
title: string;
|
||||
done?: boolean;
|
||||
dueDate: Date;
|
||||
}
|
0
src/app/todo-table/todo-table.css
Normal file
0
src/app/todo-table/todo-table.css
Normal file
31
src/app/todo-table/todo-table.html
Normal file
31
src/app/todo-table/todo-table.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
<p>todo-table works!</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Done</td>
|
||||
<td>Name</td>
|
||||
<td>Due</td>
|
||||
<td>Actions</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (task of tasks.value(); track task.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<input
|
||||
(change)="toggleTaskDoneStatus(task)"
|
||||
type="checkbox"
|
||||
name=""
|
||||
[checked]="task.done"
|
||||
/>
|
||||
</td>
|
||||
<td>{{task.title}}</td>
|
||||
<td>{{task.dueDate}}</td>
|
||||
<td>
|
||||
<button (click)="editTask(task)">Edit</button
|
||||
><button (click)="deleteTask(task)">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
23
src/app/todo-table/todo-table.spec.ts
Normal file
23
src/app/todo-table/todo-table.spec.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TodoTable } from './todo-table';
|
||||
|
||||
describe('TodoTable', () => {
|
||||
let component: TodoTable;
|
||||
let fixture: ComponentFixture<TodoTable>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TodoTable]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TodoTable);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
44
src/app/todo-table/todo-table.ts
Normal file
44
src/app/todo-table/todo-table.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { JsonPipe } from '@angular/common';
|
||||
import { Component, computed, effect, Input, resource } from '@angular/core';
|
||||
import { CreateTodo } from '../create-todo/create-todo';
|
||||
|
||||
@Component({
|
||||
selector: 'app-todo-table',
|
||||
imports: [JsonPipe, CreateTodo],
|
||||
templateUrl: './todo-table.html',
|
||||
styleUrl: './todo-table.css',
|
||||
})
|
||||
export class TodoTable {
|
||||
public tasks = resource({
|
||||
loader: async (): Promise<Task[]> => {
|
||||
const response = await fetch('http://localhost:2000/api/tasks');
|
||||
return await response.json();
|
||||
},
|
||||
});
|
||||
@Input({ required: true }) editTask!: (task: Task) => void;
|
||||
|
||||
toggleTaskDoneStatus(task: Task) {
|
||||
fetch('http://localhost:2000/api/tasks/' + task.id, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
...task,
|
||||
done: !task.done,
|
||||
}),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
deleteTask(task: Task) {
|
||||
fetch('http://localhost:2000/api/tasks/' + task.id, {
|
||||
method: 'DELETE',
|
||||
}).then(() => {
|
||||
this.tasks.reload();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
console.log(this.tasks.value());
|
||||
}
|
||||
}
|
13
src/index.html
Normal file
13
src/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Todo</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
6
src/main.ts
Normal file
6
src/main.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { App } from './app/app';
|
||||
|
||||
bootstrapApplication(App, appConfig)
|
||||
.catch((err) => console.error(err));
|
1
src/styles.css
Normal file
1
src/styles.css
Normal file
|
@ -0,0 +1 @@
|
|||
/* You can add global styles to this file, and also import other style files */
|
15
tsconfig.app.json
Normal file
15
tsconfig.app.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": []
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"src/**/*.spec.ts"
|
||||
]
|
||||
}
|
34
tsconfig.json
Normal file
34
tsconfig.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"skipLibCheck": true,
|
||||
"isolatedModules": true,
|
||||
"experimentalDecorators": true,
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"module": "preserve"
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"typeCheckHostBindings": true,
|
||||
"strictTemplates": true
|
||||
},
|
||||
"files": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
14
tsconfig.spec.json
Normal file
14
tsconfig.spec.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue