Skip to content

Commit c0a81f2

Browse files
committed
2 parents 168d9e4 + e753142 commit c0a81f2

File tree

6 files changed

+209
-168
lines changed

6 files changed

+209
-168
lines changed

src/app/features/resource-learning/modal/popup-update/resource-edit-popup.component.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { Component, EventEmitter, Input, Output } from '@angular/core';
2-
32
import { FormsModule } from '@angular/forms';
43
import { ResourceService } from '../../../../core/services/api-service/resource.service';
5-
import {
6-
ResourceData,
7-
Tag,
8-
FileCategory,
9-
MediaResource,
10-
} from '../../../../core/models/resource.model';
4+
import { MediaResource } from '../../../../core/models/resource.model';
115
import { sendNotification } from '../../../../shared/utils/notification';
12-
import { Router } from '@angular/router';
136
import { Store } from '@ngrx/store';
147
import { clearLoading } from '../../../../shared/store/loading-state/loading.action';
158
import { decodeJWT } from '../../../../shared/utils/stringProcess';
@@ -33,11 +26,7 @@ export class ResourceEditPopupComponent {
3326

3427
tagsInput: string = '';
3528

36-
constructor(
37-
private router: Router,
38-
private resourceService: ResourceService,
39-
private store: Store
40-
) {}
29+
constructor(private resourceService: ResourceService, private store: Store) {}
4130

4231
ngOnInit() {
4332
if (this.resourceId) {
@@ -50,9 +39,33 @@ export class ResourceEditPopupComponent {
5039
this.resourceService.getResourceById(id).subscribe({
5140
next: (res) => {
5241
this.resource = res.result;
53-
this.tagInput =
54-
this.resource?.tags?.map((t) => t.name).join(', ') || '';
55-
this.tags = this.resource?.tags?.map((t) => t.name) || [];
42+
// gom tất cả các name
43+
const rawNames = this.resource?.tags?.map((t) => t.name) || [];
44+
45+
// chuẩn hoá mảng tags
46+
this.tags = rawNames.flatMap((name) => {
47+
try {
48+
// nếu là JSON array
49+
if (name.includes('[')) {
50+
const parsed = JSON.parse(name);
51+
if (Array.isArray(parsed)) return parsed;
52+
}
53+
// nếu là string có dấu "
54+
if (name.includes('"')) {
55+
return name
56+
.replace(/[\[\]"]+/g, '')
57+
.split(',')
58+
.map((s) => s.trim());
59+
}
60+
// ngược lại trả về trực tiếp
61+
return [name];
62+
} catch {
63+
return [name.replace(/[\[\]"]+/g, '').trim()];
64+
}
65+
});
66+
67+
// hiển thị input (join bằng dấu phẩy)
68+
this.tagInput = this.tags.join(', ');
5669

5770
// xác định chế độ hiển thị từ orgId
5871
this.visibility =

src/app/features/resource-learning/pages/resource-create/resource-create.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export class ResourceCreatePageComponent {
119119
fileType.includes('msword') ||
120120
fileType.includes('officedocument.wordprocessingml') ||
121121
fileType.includes('presentation') ||
122-
fileType.includes('text')
122+
fileType.includes('text') ||
123+
fileType.startsWith('image/')
123124
) {
124125
category = 2;
125126
isTextbook = true;
@@ -128,10 +129,6 @@ export class ResourceCreatePageComponent {
128129
category = 1;
129130
isLectureVideo = true;
130131
}
131-
if (fileType.startsWith('image/')) {
132-
category = 0;
133-
isTextbook = true;
134-
}
135132
}
136133

137134
const postData = {

src/app/features/resource-learning/pages/resource-detail/resource-detail.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@if(resource) {
12
<div class="resource-detail-container">
23
<div
34
class="resource-detail-video"
@@ -8,7 +9,9 @@
89
>
910
<!-- Nếu là Document thì đưa Info lên trước -->
1011
<div class="resource-video-info">
11-
<div class="title">{{ resource.fileName }}</div>
12+
<div class="title">
13+
{{ resource.fileName || 'File tài nguyên học tập' }}
14+
</div>
1215
<div class="author-action">
1316
<div class="author">
1417
<div class="avatar">
@@ -132,3 +135,8 @@
132135
</div>
133136
}
134137
</div>
138+
} @if(!resource){
139+
<div class="list-post-card">
140+
<app-skeleton-loading type="card" [count]="8"></app-skeleton-loading>
141+
</div>
142+
}

src/app/features/resource-learning/pages/resource-detail/resource-detail.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,34 @@ export class ResourceDetail implements OnInit {
114114
this.resource.fileType
115115
);
116116
this.isImage = this.resource.fileType.startsWith('image/');
117-
this.tags = JSON.parse(res.result.tags[0].name);
117+
// this.tags = JSON.parse(res.result.tags[0].name);
118+
this.tags = res.result.tags.flatMap((tag) => {
119+
try {
120+
// Nếu là JSON array hợp lệ
121+
if (tag.name.includes('[') && tag.name.includes(']')) {
122+
const arr = JSON.parse(tag.name);
123+
if (Array.isArray(arr)) {
124+
return arr.map((s: string) => s.trim());
125+
}
126+
}
127+
128+
// Nếu không phải array nhưng có ký tự [, ], "
129+
if (/[\[\]"]/.test(tag.name)) {
130+
return tag.name
131+
.replace(/[\[\]"]+/g, '') // bỏ [, ], "
132+
.split(',') // tách nếu có dấu phẩy
133+
.map((s) => s.trim()) // trim khoảng trắng
134+
.filter((s) => s.length); // bỏ chuỗi rỗng
135+
}
136+
137+
// Trường hợp còn lại: trả trực tiếp
138+
return [tag.name.trim()];
139+
} catch (e) {
140+
console.error('Parse error:', e);
141+
return [tag.name.replace(/[\[\]"]+/g, '').trim()];
142+
}
143+
});
144+
118145
if (this.resource.url) {
119146
this.setSafeUrl(this.resource.url);
120147
}

src/app/features/resource-learning/pages/resource-list/resource-list.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ export class ResourceListComponent {
132132
])
133133
.pipe(
134134
map(([videosRes, docsRes]) => {
135-
const videos = videosRes.result ?? [];
135+
const videos =
136+
videosRes.result.filter(
137+
(data) => data.checksum !== 'check-sum-demo'
138+
) ?? [];
136139
const docs = docsRes.result ?? [];
137140
return [...videos, ...docs]; // gộp
138141
})

0 commit comments

Comments
 (0)