Skip to content

My excercises #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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
27 changes: 6 additions & 21 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@
"outputPath": "dist/angular-signals-course",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"polyfills": ["zone.js"],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -85,19 +78,11 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
}
}
Expand Down
10 changes: 5 additions & 5 deletions server/get-courses.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export function getAllCourses(req: Request, res: Response) {
return;
*/

console.log(`Called GET /api/courses`);

setTimeout(() => {

console.log(`Returning GET /api/courses`);
setTimeout(() => {

res.status(200).json({courses:Object.values(COURSES)});

}, 1000);
}, 1500);


}


export function getCourseById(req: Request, res: Response) {

setTimeout(() => {
Expand All @@ -33,6 +33,6 @@ export function getCourseById(req: Request, res: Response) {
const course = courses.find(course => course.id == courseId);

res.status(200).json(course);
})
}, 1500);

}
23 changes: 8 additions & 15 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
<span>resource() Demo</span>
</a>

@if(isLoggedIn()) {
<a mat-list-item (click)="onLogout()">
<mat-icon>exit_to_app</mat-icon>
<span>Logout</span>
</a>
}
@else {
<a mat-list-item routerLink="login">
<mat-icon>account_circle</mat-icon>
<span>Login</span>
</a>
}
<a mat-list-item routerLink="login">
<mat-icon>account_circle</mat-icon>
<span>Login</span>
</a>
<a mat-list-item>
<mat-icon>exit_to_app</mat-icon>
<span>Logout</span>
</a>

</mat-nav-list>

Expand All @@ -55,9 +51,6 @@

</mat-toolbar>

<messages />

<loading />

<router-outlet/>

Expand Down
7 changes: 0 additions & 7 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {MatToolbar} from "@angular/material/toolbar";
import {MatIconButton} from "@angular/material/button";
import {LoadingIndicatorComponent} from "./loading/loading.component";
import {MessagesComponent} from "./messages/messages.component";
import {AuthService} from "./services/auth.service";


@Component({
Expand All @@ -21,11 +20,5 @@ import {AuthService} from "./services/auth.service";
})
export class AppComponent {

authService = inject(AuthService);

isLoggedIn = this.authService.isLoggedIn;

onLogout() {
this.authService.logout();
}
}
6 changes: 1 addition & 5 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import {provideRouter} from '@angular/router';
import {routes} from './app.routes';
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
import { provideHttpClient, withFetch, withInterceptors } from "@angular/common/http";
import {loadingInterceptor} from "./services/loading.interceptor";

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideAnimationsAsync(),
provideHttpClient(
withFetch(),
withInterceptors([
//loadingInterceptor
])
withFetch()
)
]
};
18 changes: 2 additions & 16 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@ import {Routes} from '@angular/router';
import {HomeComponent} from "./home/home.component";
import {LoginComponent} from "./login/login.component";
import {LessonsComponent} from "./lessons/lessons.component";
import {isUserAuthenticated} from "./guards/auth.guard";
import {CourseComponent} from "./course/course.component";
import {courseResolver} from "./course/course.resolver";
import {courseLessonsResolver} from "./course/course-lessons.resolver";
import {LinkedSignalDemoComponent} from "./linked-signal/linked-signal-demo.component";
import {ResourceDemoComponent} from "./resource-demo/resource-demo.component";
import {LinkedSignalDemoComponent} from "./linked-signal/linked-signal-demo.component";

export const routes: Routes = [
{
path: '',
component: HomeComponent,
canActivate: [isUserAuthenticated]
},
{
'path': 'courses/:courseId',
component: CourseComponent,
canActivate: [isUserAuthenticated],
resolve: {
course: courseResolver,
lessons: courseLessonsResolver
}
component: HomeComponent
},
{
path: "login",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

<div class="form-control">

<label>{{label()}}</label>
<label></label>

<select [value]="value()" #category
(change)="onCategoryChanged(category.value)">
<select #category>
<option value="BEGINNER">Beginners</option>
<option value="INTERMEDIATE">Intermediate</option>
<option value="ADVANCED">Advanced</option>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import {Component, input, model} from '@angular/core';
import {CourseCategory} from "../models/course-category.model";
import { Component, input, model } from '@angular/core';
import { CourseCategory } from '../models/course-category.model';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { EditCourseDialogData } from '../edit-course-dialog/edit-course-dialog.data.model';
import { EditCourseDialogComponent } from '../edit-course-dialog/edit-course-dialog.component';

@Component({
selector: 'course-category-combobox',
imports: [],
templateUrl: './course-category-combobox.component.html',
styleUrl: './course-category-combobox.component.scss'
selector: 'course-category-combobox',
standalone: true,
imports: [],
templateUrl: './course-category-combobox.component.html',
styleUrl: './course-category-combobox.component.scss',
})
export class CourseCategoryComboboxComponent {

label = input.required<string>();

value = model.required<CourseCategory>();

onCategoryChanged(category: string) {
this.value.set(category as CourseCategory);
}

}
16 changes: 0 additions & 16 deletions src/app/course/course-lessons.resolver.ts

This file was deleted.

21 changes: 1 addition & 20 deletions src/app/course/course.component.html
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
<div class="course-container">
<div class="course-header">
<h1>{{ course()?.title }}</h1>
<img class="course-image" [src]="course()?.iconUrl">
</div>
<div class="table-container">
<table class="results-table">
@for(lesson of lessons(); track lesson.id) {
<tr>
<td>
{{lesson.description}}
</td>
<td>
{{lesson.duration}}
</td>
</tr>
}
</table>
</div>
</div>
<p>course works!</p>
26 changes: 7 additions & 19 deletions src/app/course/course.component.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import {Component, inject, OnInit, signal} from '@angular/core';
import {Course} from "../models/course.model";
import {Lesson} from "../models/lesson.model";
import {ActivatedRoute} from "@angular/router";
import { Component } from '@angular/core';

@Component({
selector: 'course',
imports: [],
templateUrl: './course.component.html',
styleUrl: './course.component.scss'
selector: 'course',
standalone: true,
imports: [],
templateUrl: './course.component.html',
styleUrl: './course.component.scss'
})
export class CourseComponent implements OnInit {
export class CourseComponent {

course = signal<Course | null>(null);

lessons = signal<Lesson[]>([]);

route = inject(ActivatedRoute);

ngOnInit() {
this.course.set(this.route.snapshot.data["course"]);
this.lessons.set(this.route.snapshot.data["lessons"]);
}
}
16 changes: 0 additions & 16 deletions src/app/course/course.resolver.ts

This file was deleted.

39 changes: 19 additions & 20 deletions src/app/courses-card-list/courses-card-list.component.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
@for(course of courses() ;track course.id){

@for(course of courses(); track course.id) {
<div class="course-card">
<div class="course-header">
<span class="course-title">{{course.title}}</span>
</div>
<img class="course-image" [src]="course.iconUrl">
<div class="course-description">
<p>{{course.longDescription}}</p>
</div>
<div class="course-actions">
<button class="btn"
[routerLink]="['courses', course.id]" >
VIEW COURSE
</button>
<button class="btn" (click)="onEditCourse(course)">
EDIT
</button>
<img class="delete" src="/assets/icons/delete.svg"
(click)="onCourseDeleted(course)">
</div>
<div class="course-card">
<div class="course-header">
<span class="course-title">{{ course.title }}</span>
</div>
<img class="course-image" [src]="course.iconUrl" alt="" />
<div class="course-description">
<p>{{ course.longDescription }}</p>
</div>
<div class="course-actions">
<button class="btn">
VIEW COURSE
</button>
<button class="btn" (click)="onEdiCourse(course)">
EDIT
</button>
<img class="delete" src="/assets/icons/delete.svg">
</div>
</div>

}
Loading