2018-05-12 23:55:02 -04:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
|
|
|
import { FE_StickerPack } from "../../shared/models/integration";
|
|
|
|
import { AdminStickersApiService } from "../../shared/services/admin/admin-stickers-api-service";
|
2021-08-16 18:00:59 -04:00
|
|
|
import { AdminStickerPackPreviewComponent, StickerPackPreviewMoadlInstance } from "./preview/preview.component";
|
|
|
|
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2018-05-12 23:55:02 -04:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./sticker-packs.component.html",
|
|
|
|
styleUrls: ["./sticker-packs.component.scss"],
|
|
|
|
})
|
|
|
|
export class AdminStickerPacksComponent implements OnInit {
|
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public isUpdating = false;
|
|
|
|
public packs: FE_StickerPack[];
|
2018-12-22 19:37:31 -05:00
|
|
|
public tgUrl: string;
|
|
|
|
public isImporting = false;
|
2018-05-12 23:55:02 -04:00
|
|
|
|
|
|
|
constructor(private adminStickers: AdminStickersApiService,
|
|
|
|
private toaster: ToasterService,
|
2021-08-16 18:00:59 -04:00
|
|
|
private modal: NgbModal,
|
2020-10-23 07:30:20 -04:00
|
|
|
public translate: TranslateService) {
|
|
|
|
this.translate = translate;
|
2018-05-12 23:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.adminStickers.getAllPacks().then(packs => {
|
|
|
|
this.packs = packs;
|
|
|
|
this.isLoading = false;
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Failed to load sticker packs').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2018-05-12 23:55:02 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public toggleEnabled(pack: FE_StickerPack) {
|
|
|
|
pack.isEnabled = !pack.isEnabled;
|
|
|
|
this.isUpdating = true;
|
|
|
|
this.adminStickers.togglePack(pack.id, pack.isEnabled).then(() => {
|
|
|
|
this.isUpdating = false;
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Sticker pack updated').subscribe((res: string) => {this.toaster.pop("success", res); });
|
2018-05-12 23:55:02 -04:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
pack.isEnabled = !pack.isEnabled; // revert change
|
|
|
|
this.isUpdating = false;
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Error updating sticker pack').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2018-05-12 23:55:02 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public previewStickers(pack: FE_StickerPack) {
|
2021-08-16 18:00:59 -04:00
|
|
|
const modalRef = this.modal.open(AdminStickerPackPreviewComponent, { size: 'lg' });
|
|
|
|
const previewInstance = modalRef.componentInstance as StickerPackPreviewMoadlInstance;
|
2018-05-12 23:55:02 -04:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
previewInstance.pack = pack;
|
2018-05-12 23:55:02 -04:00
|
|
|
}
|
2018-12-22 19:37:31 -05:00
|
|
|
|
|
|
|
public startTelegramImport() {
|
|
|
|
this.isImporting = true;
|
|
|
|
this.adminStickers.importFromTelegram(this.tgUrl).then(pack => {
|
|
|
|
this.isImporting = false;
|
|
|
|
this.tgUrl = "";
|
|
|
|
this.packs.push(pack);
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Telegram sticker pack imported').subscribe((res: string) => {this.toaster.pop("success", res); });
|
2018-12-22 19:37:31 -05:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isImporting = false;
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate.get('Error importing sticker pack').subscribe((res: string) => {this.toaster.pop("error", res); });
|
2018-12-22 19:37:31 -05:00
|
|
|
});
|
|
|
|
}
|
2020-08-01 09:50:14 -04:00
|
|
|
|
|
|
|
public removePack(pack: FE_StickerPack) {
|
|
|
|
this.isUpdating = true;
|
|
|
|
this.adminStickers.removePack(pack.id).then(() => {
|
2020-12-28 22:31:34 -05:00
|
|
|
for (let i = 0; i < this.packs.length; ++i) {
|
2020-08-01 09:50:14 -04:00
|
|
|
if (this.packs[i].id === pack.id) {
|
|
|
|
this.packs.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-28 22:31:34 -05:00
|
|
|
}
|
2020-08-01 09:50:14 -04:00
|
|
|
this.isUpdating = false;
|
|
|
|
this.toaster.pop("success", "Sticker pack removed");
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isUpdating = false;
|
|
|
|
this.toaster.pop("error", "Error removing sticker pack");
|
|
|
|
});
|
|
|
|
}
|
2018-05-12 23:55:02 -04:00
|
|
|
}
|