diff --git a/src/app/pages/blank/blank.module.ts b/src/app/pages/blank/blank.module.ts index e1e2725..935ec37 100644 --- a/src/app/pages/blank/blank.module.ts +++ b/src/app/pages/blank/blank.module.ts @@ -4,12 +4,16 @@ import { BlankComponent } from './blank.component'; import { BlankInfoComponent } from './shared/components/blank-info/blank-info.component'; import { RouterModule, Routes } from "@angular/router"; import { SharedModule } from "../../shared/shared.module"; +import { BlankInvalidInfoComponent } from './shared/components/blank-invalid-info/blank-invalid-info.component'; const routes: Routes = [ { path: '', component: BlankComponent, children: [ { path: ':id', component: BlankInfoComponent, pathMatch: 'full' + }, + { + path: 'wrong/:id', component: BlankInfoComponent, pathMatch: 'full' } ] } @@ -18,7 +22,8 @@ const routes: Routes = [ @NgModule({ declarations: [ BlankComponent, - BlankInfoComponent + BlankInfoComponent, + BlankInvalidInfoComponent, ], imports: [ CommonModule, diff --git a/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.html b/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.html new file mode 100644 index 0000000..6f18718 --- /dev/null +++ b/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.html @@ -0,0 +1 @@ +

blank-invalid-info works!

diff --git a/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.scss b/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.ts b/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.ts new file mode 100644 index 0000000..9b7f079 --- /dev/null +++ b/src/app/pages/blank/shared/components/blank-invalid-info/blank-invalid-info.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-blank-invalid-info', + templateUrl: './blank-invalid-info.component.html', + styleUrls: ['./blank-invalid-info.component.scss'] +}) +export class BlankInvalidInfoComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/src/app/pages/test/shared/components/test-info/test-info.component.html b/src/app/pages/test/shared/components/test-info/test-info.component.html index 1140d81..eda8303 100644 --- a/src/app/pages/test/shared/components/test-info/test-info.component.html +++ b/src/app/pages/test/shared/components/test-info/test-info.component.html @@ -82,46 +82,57 @@

- + - +
- - - +

+ Непроверенные бланки +

- +
    - - - - - + +
  • +
    + {{ i + 1 }}. +
    + + - - - - - - - +
    + {{ blank.created_at.getDate() | number:'2.0' }}.{{ blank.created_at.getMonth() + 1 | number:'2.0' }}.{{ blank.created_at.getFullYear() }} +
    - - - + - - - - +
  • +
    - - +
- - +
+
+ + удалить все + +
+
+
- +
diff --git a/src/app/pages/test/shared/components/test-info/test-info.component.scss b/src/app/pages/test/shared/components/test-info/test-info.component.scss index 1f44ce6..6801527 100644 --- a/src/app/pages/test/shared/components/test-info/test-info.component.scss +++ b/src/app/pages/test/shared/components/test-info/test-info.component.scss @@ -340,6 +340,10 @@ &__right { color: $textGrey; } + + &__buttons { + margin-top: 2rem; + } } .test-assessment { diff --git a/src/app/pages/test/shared/components/test-info/test-info.component.ts b/src/app/pages/test/shared/components/test-info/test-info.component.ts index 1d7897e..75ea868 100644 --- a/src/app/pages/test/shared/components/test-info/test-info.component.ts +++ b/src/app/pages/test/shared/components/test-info/test-info.component.ts @@ -137,22 +137,22 @@ export class TestInfoComponent implements OnInit { }) } - protected deleteWrongBlank(i: number) { - const blank = this.test.wrongBlanks[i] + protected deleteInvalidBlank(i: number) { + const blank = this.test.invalidBlanks[i] this._confirmService.createConfirm({ message: `Вы действительно хотите удалить бланк от ${ - (blank.createdAt.getDate() < 10 ? '0' : '') + blank.createdAt.getDate()}.${ - (blank.createdAt.getMonth() + 1 < 10 ? '0' : '') + (blank.createdAt.getMonth() + 1)}.${ - blank.createdAt.getFullYear()}?`, + (blank.created_at.getDate() < 10 ? '0' : '') + blank.created_at.getDate()}.${ + (blank.created_at.getMonth() + 1 < 10 ? '0' : '') + (blank.created_at.getMonth() + 1)}.${ + blank.created_at.getFullYear()}?`, buttonText: 'удалить' }) .subscribe(confirmed => { if (!confirmed) return - this._blankService.deleteWrongBlank(blank.pk) + this._blankService.deleteInvalidBlank(blank.pk) .subscribe(() => { - this.test.wrongBlanks.splice(i, 1) + this.test.invalidBlanks.splice(i, 1) this._cd.markForCheck() }) }) @@ -169,11 +169,28 @@ export class TestInfoComponent implements OnInit { this._router.navigate(['blank', pkBlank], extras) } - protected showWrongBlank(pkBlank: number) { + protected showInvalidBlank(pkBlank: number) { // todo } protected navigateClass() { this._router.navigate(['/', 'class', this.classInfo.pk]) } + + protected deleteAllInvalid() { + this._confirmService.createConfirm({ + message: `Вы действительно хотите удалить все непроверенные бланки?`, + buttonText: 'удалить' + }) + .subscribe(confirmed => { + if (!confirmed) + return + + this._blankService.deleteInvalidBlanks(this.test.invalidBlanks) + .subscribe(() => { + this.test.invalidBlanks = [] + this._cd.markForCheck() + }) + }) + } } diff --git a/src/app/pages/test/shared/components/test-result/test-result.component.ts b/src/app/pages/test/shared/components/test-result/test-result.component.ts index fe50abd..86024a0 100644 --- a/src/app/pages/test/shared/components/test-result/test-result.component.ts +++ b/src/app/pages/test/shared/components/test-result/test-result.component.ts @@ -44,6 +44,6 @@ export class TestResultComponent implements OnInit { } protected navigateTest() { - this._router.navigate(['/', 'test', this.blanks[0].test]) + this._router.navigate(['/', 'test', getParamFromRoute(this._route)]) } } diff --git a/src/app/shared/components/blank-view/blank-view.component.ts b/src/app/shared/components/blank-view/blank-view.component.ts index ab1424d..360e14e 100644 --- a/src/app/shared/components/blank-view/blank-view.component.ts +++ b/src/app/shared/components/blank-view/blank-view.component.ts @@ -48,6 +48,7 @@ export class BlankViewComponent implements OnChanges { if (!changes?.['view']?.currentValue) return + console.log(this.view) this.resultView = calculateResult(changes?.['view']?.currentValue.blank) } diff --git a/src/app/shared/components/blanks-view/blanks-view.component.ts b/src/app/shared/components/blanks-view/blanks-view.component.ts index ff8d12b..3c42ead 100644 --- a/src/app/shared/components/blanks-view/blanks-view.component.ts +++ b/src/app/shared/components/blanks-view/blanks-view.component.ts @@ -45,11 +45,13 @@ export class BlanksViewComponent implements AfterViewInit, OnChanges { if (!changes?.['blanks'].currentValue || changes?.['blanks'].firstChange) return - this.createView(this.blanks[this.showIndex], this._showDetail) + if (this.blanks.length > this.showIndex) + this.createView(this.blanks[this.showIndex], this._showDetail) } public ngAfterViewInit(): void { - this.createView(this.blanks[this.showIndex]) + if (this.blanks.length > this.showIndex) + this.createView(this.blanks[this.showIndex]) } private createView(blank: IBlankParsed, showDetail: boolean = false) { diff --git a/src/app/shared/functions/blanks/translateWrongBlanksFromRequest.ts b/src/app/shared/functions/blanks/translateInvalidBlanksFromRequest.ts similarity index 61% rename from src/app/shared/functions/blanks/translateWrongBlanksFromRequest.ts rename to src/app/shared/functions/blanks/translateInvalidBlanksFromRequest.ts index b50fb62..99819ba 100644 --- a/src/app/shared/functions/blanks/translateWrongBlanksFromRequest.ts +++ b/src/app/shared/functions/blanks/translateInvalidBlanksFromRequest.ts @@ -1,9 +1,9 @@ import { IBlankInvalidRequest } from "../../interfaces/Tests/Blanks/IBlankInvalidRequest"; import { IBlankInvalidParsed } from "../../interfaces/Tests/Blanks/IBlankInvalidParsed"; -export function translateWrongBlanksFromRequest(blanks: IBlankInvalidRequest[]): IBlankInvalidParsed[] { +export function translateInvalidBlanksFromRequest(blanks: IBlankInvalidRequest[]): IBlankInvalidParsed[] { return blanks.map(blank => ({ ...blank, - createdAt: new Date(blank.createdAt) + created_at: new Date(blank.created_at) })) } diff --git a/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidParsed.ts b/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidParsed.ts index 9e246b2..f6c60c1 100644 --- a/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidParsed.ts +++ b/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidParsed.ts @@ -1,5 +1,5 @@ export interface IBlankInvalidParsed { pk: number - createdAt: Date + created_at: Date image: string } diff --git a/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidRequest.ts b/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidRequest.ts index be2e27a..e04f3a6 100644 --- a/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidRequest.ts +++ b/src/app/shared/interfaces/Tests/Blanks/IBlankInvalidRequest.ts @@ -1,5 +1,5 @@ export interface IBlankInvalidRequest { pk: number - createdAt: number + created_at: number image: string } diff --git a/src/app/shared/interfaces/Tests/Tests/ITestAllInfo.ts b/src/app/shared/interfaces/Tests/Tests/ITestAllInfo.ts index 592eac7..7427450 100644 --- a/src/app/shared/interfaces/Tests/Tests/ITestAllInfo.ts +++ b/src/app/shared/interfaces/Tests/Tests/ITestAllInfo.ts @@ -4,5 +4,5 @@ import { IBlankInvalidParsed } from "../Blanks/IBlankInvalidParsed"; export interface ITestAllInfo extends ITest { blanks: IBlankParsed[] - wrongBlanks: IBlankInvalidParsed[] + invalidBlanks: IBlankInvalidParsed[] } diff --git a/src/app/shared/services/blank.service.ts b/src/app/shared/services/blank.service.ts index 2b70496..623d884 100644 --- a/src/app/shared/services/blank.service.ts +++ b/src/app/shared/services/blank.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpService } from "./infrastructure/http.service"; import { IBlankRequest } from "../interfaces/Tests/Blanks/IBlankRequest"; -import { delay, forkJoin, map, Observable, of, switchMap, take } from "rxjs"; +import { forkJoin, map, Observable, of, switchMap, take, zip } from "rxjs"; import { IBlankParsed } from "../interfaces/Tests/Blanks/IBlankParsed"; import { environment } from "../../../environments/environment"; import { IBlankWithAuthor } from "../interfaces/Tests/Blanks/IBlankWithAuthor"; @@ -10,8 +10,9 @@ import { StudentService } from "./student.service"; import { PatternService } from "./pattern.service"; import { sortStrings } from "../functions/application/sortStrings"; import { IBlankInvalidParsed } from "../interfaces/Tests/Blanks/IBlankInvalidParsed"; -import { translateWrongBlanksFromRequest } from "../functions/blanks/translateWrongBlanksFromRequest"; +import { translateInvalidBlanksFromRequest } from "../functions/blanks/translateInvalidBlanksFromRequest"; import { BlankUpdate } from "../interfaces/Tests/Blanks/BlankUpdate"; +import { IBlankInvalidRequest } from "../interfaces/Tests/Blanks/IBlankInvalidRequest"; @Injectable({ providedIn: 'root' @@ -23,8 +24,8 @@ export class BlankService { private _pattern: PatternService ) { } - public deleteBlank(blankPk: number): Observable { - return this._http.Delete(`blank/${blankPk}`) + public deleteBlank(pkBlank: number): Observable { + return this._http.Delete(`blank/${pkBlank}`) .pipe(take(1)) } @@ -39,38 +40,26 @@ export class BlankService { ) } - public getWrongBlanks(pkTest: number): Observable { - return of([ - { - pk: 1, - createdAt: Date.now(), - image: "", - }, - { - pk: 1, - createdAt: new Date().setDate(new Date().getDate() - 7), - image: "", - }, - { - pk: 1, - createdAt: new Date().setDate(new Date().getDate() - 14), - image: "", - }, - { - pk: 1, - createdAt: new Date().setDate(new Date().getDate() - 21), - image: "", - }]) + public getInvalidBlanks(pkTest: number, temporary = false): Observable { + return this._http.Get( + (temporary ? "temp/" : "") + `test/${pkTest}/invalid_blanks`, + { withCredentials: !temporary } + ) .pipe( - map(blanks => translateWrongBlanksFromRequest(blanks)), - take(1), + map(blanks => translateInvalidBlanksFromRequest(blanks)), + take(1) ) } - public deleteWrongBlank(pkBlank: number): Observable { - return of({}) + public deleteInvalidBlank(pkBlank: number): Observable { + return this._http.Delete(`invalid_blank/${pkBlank}`) + .pipe(take(1)) + } + + public deleteInvalidBlanks(blanks: IBlankInvalidParsed[]): Observable { + return zip(...blanks.map(blank => this.deleteInvalidBlank(blank.pk))) .pipe( - delay(100), + map(() => undefined), take(1) ) } diff --git a/src/app/shared/services/test.service.ts b/src/app/shared/services/test.service.ts index 409662e..b8fadab 100644 --- a/src/app/shared/services/test.service.ts +++ b/src/app/shared/services/test.service.ts @@ -28,7 +28,7 @@ export class TestService { switchMap(test => { return forkJoin({ blanks: this._blank.getBlanks(pkTest), - wrongBlanks: this._blank.getWrongBlanks(pkTest), + invalidBlanks: this._blank.getInvalidBlanks(pkTest), }) .pipe( map(blanksAll => ({ diff --git a/src/styles/classes.scss b/src/styles/classes.scss index e7102da..ba8ebfc 100644 --- a/src/styles/classes.scss +++ b/src/styles/classes.scss @@ -66,7 +66,7 @@ %block-red { border-radius: 35px; - border: 4.045px solid $red; + border: 3px solid $red; background: #F6F6F6; box-shadow: 4.44px 6.21px 16.86px 0px rgba(0, 0, 0, 0.25); padding: 2.5rem 2.9rem;