@@ -4,7 +4,7 @@ import format from 'date-fns/format';
4
4
import formatDistanceStrict from 'date-fns/formatDistanceStrict' ;
5
5
import zhCN from 'date-fns/locale/zh-CN' ;
6
6
import { TreeItem , TreeItemCollapsibleState , ThemeIcon } from 'vscode' ;
7
- import { Post } from '../../models/post' ;
7
+ import { AccessPermission , Post , formatAccessPermission } from '../../models/post' ;
8
8
import { PostEditDto } from '../../models/post-edit-dto' ;
9
9
import { postCategoryService } from '../../services/post-category.service' ;
10
10
import { postService } from '../../services/post.service' ;
@@ -17,6 +17,8 @@ export enum RootPostMetadataType {
17
17
tagEntry = 'tagEntry' ,
18
18
updateDate = 'updateDate' ,
19
19
createDate = 'createDate' ,
20
+ publishStatus = 'publishStatus' ,
21
+ accessPermission = 'accessPermission' ,
20
22
}
21
23
22
24
const rootMetadataMap = ( parsedPost : Post , postEditDto : PostEditDto | undefined ) =>
@@ -26,6 +28,8 @@ const rootMetadataMap = (parsedPost: Post, postEditDto: PostEditDto | undefined)
26
28
( ) => ( parsedPost . hasUpdates ? new PostUpdatedDateMetadata ( parsedPost ) : null ) ,
27
29
] ,
28
30
[ RootPostMetadataType . createDate , ( ) => new PostCreatedDateMetadata ( parsedPost ) ] ,
31
+ [ RootPostMetadataType . publishStatus , ( ) => new PostPublishStatusMetadata ( parsedPost ) ] ,
32
+ [ RootPostMetadataType . accessPermission , ( ) => new PostAccessPermissionMetadata ( parsedPost ) ] ,
29
33
[
30
34
RootPostMetadataType . categoryEntry ,
31
35
( ) =>
@@ -206,3 +210,58 @@ export class PostUpdatedDateMetadata extends PostDateMetadata {
206
210
return differenceInSeconds ( dateUpdated ?? now , datePublished ?? now ) > 0 ;
207
211
}
208
212
}
213
+
214
+ export class PostAccessPermissionMetadata extends PostMetadata {
215
+ constructor ( public readonly parent : Post ) {
216
+ super ( parent ) ;
217
+ }
218
+
219
+ static parseIcon ( accessPermission : AccessPermission , requirePassword : boolean ) {
220
+ if ( requirePassword ) return new ThemeIcon ( 'key' ) ;
221
+
222
+ switch ( accessPermission ) {
223
+ case AccessPermission . undeclared :
224
+ return new ThemeIcon ( 'globe' ) ;
225
+ case AccessPermission . authenticated :
226
+ return new ThemeIcon ( 'public-ports-view-icon' ) ;
227
+ default :
228
+ return new ThemeIcon ( 'private-ports-view-icon' ) ;
229
+ }
230
+ }
231
+
232
+ toTreeItem ( ) : Promise < TreeItem > {
233
+ const { password } = this . parent ;
234
+ const isPasswordRequired = password != null && password . length > 0 ;
235
+ return Promise . resolve (
236
+ Object . assign < TreeItem , Partial < TreeItem > > (
237
+ new TreeItem (
238
+ `访问权限: ${ formatAccessPermission ( this . parent . accessPermission ) } ` +
239
+ ( isPasswordRequired ? '(需密码)' : '' )
240
+ ) ,
241
+ {
242
+ iconPath : PostAccessPermissionMetadata . parseIcon ( this . parent . accessPermission , isPasswordRequired ) ,
243
+ }
244
+ )
245
+ ) ;
246
+ }
247
+ }
248
+
249
+ export class PostPublishStatusMetadata extends PostMetadata {
250
+ constructor ( public readonly parent : Post ) {
251
+ super ( parent ) ;
252
+ }
253
+
254
+ toTreeItem ( ) : Promise < TreeItem > {
255
+ const {
256
+ parent : { isPublished, isDraft } ,
257
+ } = this ;
258
+ return Promise . resolve (
259
+ Object . assign < TreeItem , Partial < TreeItem > > (
260
+ new TreeItem ( isPublished ? '已发布' : '未发布' + ( isDraft ? '(草稿)' : '' ) ) ,
261
+ {
262
+ iconPath : new ThemeIcon ( isDraft ? 'issue-draft' : isPublished ? 'issue-closed' : 'circle-slash' ) ,
263
+ }
264
+ )
265
+ ) ;
266
+ }
267
+ }
0 commit comments