10 changed files with 340 additions and 41 deletions
@ -0,0 +1,249 @@ |
|||
import {Component, Inject, Input} from "@angular/core"; |
|||
import {MAT_DIALOG_DATA} from "@angular/material/dialog"; |
|||
import {HttpClient} from "@angular/common/http"; |
|||
import {Player} from "../../../entities/servers/Player"; |
|||
import {map} from "rxjs"; |
|||
import {SteamIDs} from "../../../entities/profile/SteamIDs"; |
|||
|
|||
@Component({ |
|||
selector: 'app-report-create-dialog', |
|||
template: ` |
|||
<div [ngSwitch]="data.mode"> |
|||
<div *ngSwitchDefault> |
|||
<h1 mat-dialog-title style="color: black">Что-то пошло не так</h1> |
|||
<mat-dialog-content> |
|||
<p>Не выбран режим работы окна</p> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
<div *ngSwitchCase="'report'"> |
|||
<h1 mat-dialog-title style="color: black">Создать жалобу</h1> |
|||
<mat-dialog-content> |
|||
<p>{{response}}</p> |
|||
<mat-form-field style="width: 100%" appearance="fill"> |
|||
<mat-label>Причина тряски</mat-label> |
|||
<input matInput placeholder="Путис" [(ngModel)]="text" [disabled]="loading"> |
|||
</mat-form-field> |
|||
<button |
|||
[disabled]="text.length<1 || loading" |
|||
mat-button |
|||
mat-raised-button |
|||
style="width: 100%" |
|||
(click)="sendReport()">Пожаловаться</button> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
<div *ngSwitchCase="'ban'"> |
|||
<h1 mat-dialog-title style="color: black">Бан</h1> |
|||
<mat-dialog-content> |
|||
<p>{{response}}</p> |
|||
<mat-form-field style="width: 100%" appearance="fill"> |
|||
<mat-label>Причина бана</mat-label> |
|||
<input matInput placeholder="Хохол" [(ngModel)]="text" [disabled]="loading"> |
|||
</mat-form-field> |
|||
<mat-form-field style="width: 100%" appearance="fill"> |
|||
<mat-label>Длительность бана в минутах, 0 - навсегда</mat-label> |
|||
<input matInput placeholder="0" type="number" [(ngModel)]="number" [disabled]="loading"> |
|||
</mat-form-field> |
|||
<button |
|||
[disabled]="text.length<1 || loading" |
|||
mat-button |
|||
mat-raised-button |
|||
style="width: 100%" |
|||
(click)="sendBan()">Забанить</button> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
<div *ngSwitchCase="'kick'"> |
|||
<h1 mat-dialog-title style="color: black">Кикаем игрока</h1> |
|||
<mat-dialog-content> |
|||
<p>{{response}}</p> |
|||
<mat-form-field style="width: 100%" appearance="fill"> |
|||
<mat-label>Причина кика</mat-label> |
|||
<input matInput placeholder="Мешает какать" [(ngModel)]="text" [disabled]="loading"> |
|||
</mat-form-field> |
|||
<button |
|||
[disabled]="text.length<1 || loading" |
|||
mat-button |
|||
mat-raised-button |
|||
style="width: 100%" |
|||
(click)="sendKick()">Кикнуть</button> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
<div *ngSwitchCase="'mute'"> |
|||
<h1 mat-dialog-title style="color: black">Выключаем микрофон</h1> |
|||
<mat-dialog-content> |
|||
<p [style]="response == 'Введи причину, чем она понятнее тем лучше'?'display: none':''">{{response}}</p> |
|||
<button |
|||
[disabled]="loading" |
|||
mat-button |
|||
mat-raised-button |
|||
style="width: 100%" |
|||
(click)="sendMute()">Выключить микрофон</button> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
<div *ngSwitchCase="'unban'"> |
|||
<h1 mat-dialog-title style="color: black">Разбанить игрока</h1> |
|||
<mat-dialog-content> |
|||
<p [style]="response == 'Введи причину, чем она понятнее тем лучше'?'display: none':''">{{response}}</p> |
|||
<button |
|||
[disabled]="loading" |
|||
mat-button |
|||
mat-raised-button |
|||
style="width: 100%" |
|||
(click)="sendUnban()">Разбанить</button> |
|||
</mat-dialog-content> |
|||
<mat-dialog-actions> |
|||
<button mat-button mat-raised-button mat-dialog-close="true" style="width: 100%">Закрыть</button> |
|||
</mat-dialog-actions> |
|||
</div> |
|||
</div> |
|||
` |
|||
}) |
|||
export class SimpleActionDialog { |
|||
text: string = ""; |
|||
number: number = 0; |
|||
response: string = "Введи причину, чем она понятнее тем лучше"; |
|||
loading: boolean = false; |
|||
|
|||
constructor(@Inject(MAT_DIALOG_DATA) public data: { |
|||
steamIds: SteamIDs, |
|||
mode: string |
|||
}, |
|||
private http: HttpClient) {} |
|||
|
|||
sendReport() { |
|||
this.response = 'Отправляем....' |
|||
this.loading = true; |
|||
this.http.post(`api/profile/current/report?steam64=${this.data.steamIds.steam64}&text=${this.text}`, {}) |
|||
.pipe(map(res => Number.parseInt(`${res}`))) |
|||
.subscribe( |
|||
(res) => { |
|||
if (res > 0) this.response = 'Репорт успешно отослан' |
|||
else if (res < 0) this.response = `Перед другим репортом нужно подождать ${res*-1} секунд`; |
|||
else this.response = 'Произошла ошибка, нельзя опубликовать жалобу'; |
|||
this.loading = false; |
|||
}, |
|||
(error) => { |
|||
if (error.status == 406) this.response = 'Ты в бане, жалобу отправить нельзя!' |
|||
else this.response = 'Неизвестная ошибка, терпи...'; |
|||
this.loading = false; |
|||
}) |
|||
} |
|||
|
|||
sendKick() { |
|||
this.response = "Кикаем..."; |
|||
this.loading = true; |
|||
this.http.post(`api/admin/kick?steam64=${this.data.steamIds.steam64}`, {}) |
|||
.subscribe( |
|||
(res) => { |
|||
this.loading = false; |
|||
this.response = 'Успешно кикнут'; |
|||
}, (err) => { |
|||
switch (err.status) { |
|||
case 404: { |
|||
this.response = "Такого игрока уже нет на сервере"; |
|||
break; |
|||
} |
|||
default: { |
|||
this.response = "Неизвестная ошибка, ты новичек??"; |
|||
break; |
|||
} |
|||
} |
|||
this.loading = false; |
|||
} |
|||
) |
|||
} |
|||
|
|||
sendMute() { |
|||
this.response = "Выключаем микрофон..."; |
|||
this.loading = true; |
|||
this.http.post(`api/admin/mute?steam64=${this.data.steamIds.steam64}`, {}) |
|||
.subscribe( |
|||
(res) => { |
|||
this.loading = false; |
|||
this.response = 'Успешно выключен микрофон'; |
|||
}, (err) => { |
|||
switch (err.status) { |
|||
case 404: { |
|||
this.response = "Такого игрока уже нет на сервере"; |
|||
break; |
|||
} |
|||
default: { |
|||
this.response = "Неизвестная ошибка, ты новичек??"; |
|||
break; |
|||
} |
|||
} |
|||
this.loading = false; |
|||
} |
|||
) |
|||
} |
|||
|
|||
sendUnban() { |
|||
this.response = "Пробуем разбанить"; |
|||
this.loading = true; |
|||
this.http.delete(`api/admin/ban?steam64=${this.data.steamIds.steam64}`, {}) |
|||
.subscribe( |
|||
(res) => { |
|||
this.loading = false; |
|||
this.response = 'Успешно разбанил'; |
|||
}, (err) => { |
|||
switch (err.status) { |
|||
case 404: { |
|||
this.response = "А такого бана нет"; |
|||
break; |
|||
} |
|||
default: { |
|||
this.response = "Неизвестная ошибка, ты новичек??"; |
|||
break; |
|||
} |
|||
} |
|||
this.loading = false; |
|||
} |
|||
) |
|||
} |
|||
|
|||
sendBan() { |
|||
this.response = "Баним..."; |
|||
this.loading = true; |
|||
this.http.post(`api/admin/ban?steam64=${this.data.steamIds.steam64}&ban_length=${this.number}&ban_reason=${this.text}`, {}) |
|||
.subscribe( |
|||
(res) => { |
|||
this.loading = false; |
|||
}, |
|||
(err) => { |
|||
switch (err.status) { |
|||
case 201: { |
|||
this.response = 'Успешно забанен!'; |
|||
break; |
|||
} |
|||
case 202: { |
|||
this.response = 'Уже в бане, нельзя забанить повторно'; |
|||
break; |
|||
} |
|||
case 406: { |
|||
this.response = 'Чел... Он слишком крут для тебя'; |
|||
break; |
|||
} |
|||
default: { |
|||
this.response = 'Неизвестная ошибка, ты новичек??'; |
|||
break; |
|||
} |
|||
} |
|||
this.loading = false; |
|||
} |
|||
) |
|||
} |
|||
} |
Loading…
Reference in new issue