@@ -2,7 +2,7 @@ import { MarkdownPostProcessorContext } from "obsidian"
2
2
import { createProxy , IJiraIssue , IJiraSearchResults } from "./interfaces"
3
3
import { JiraClient } from "./jiraClient"
4
4
import { ObjectsCache } from "./objectsCache"
5
- import { ESearchResultsRenderingTypes , IJiraIssueSettings } from "./settings"
5
+ import { ESearchColumnsTypes , ESearchResultsRenderingTypes , IJiraIssueSettings , SEARCH_COLUMNS_DESCRIPTION } from "./settings"
6
6
7
7
const COMMENT_REGEX = / ^ \s * # /
8
8
const ISSUE_REGEX = / ^ \s * ( [ A - Z 0 - 9 ] + - [ 0 - 9 ] + ) \s * $ / i
@@ -197,43 +197,116 @@ export class JiraIssueProcessor {
197
197
198
198
private renderSearchResultsTable ( el : HTMLElement , query : string , searchResults : IJiraSearchResults ) : void {
199
199
const table = createEl ( 'table' , { cls : `table is-bordered is-striped is-narrow is-hoverable is-fullwidth ${ this . getTheme ( ) } ` } )
200
+ this . renderSearchResultsTableHeader ( table )
201
+ this . renderSearchResultsTableBody ( table , searchResults )
202
+ const statistics = createSpan ( { cls : 'statistics' , text : `Total results: ${ searchResults . total . toString ( ) } - Last update: ${ this . _cache . getTime ( query ) } ` } )
203
+ el . replaceChildren ( this . renderContainer ( [ table , statistics ] ) )
204
+ }
205
+
206
+ private renderSearchResultsTableHeader ( table : HTMLElement ) : void {
200
207
const header = createEl ( 'tr' , { parent : createEl ( 'thead' , { parent : table } ) } )
201
- createEl ( 'th' , { text : 'Key' , parent : header } )
202
- createEl ( 'th' , { text : 'Summary' , parent : header } )
203
- createEl ( 'abbr' , { text : 'T' , title : 'Type' , parent : createEl ( 'th' , { parent : header } ) } )
204
- createEl ( 'th' , { text : 'Created' , parent : header } )
205
- createEl ( 'th' , { text : 'Updated' , parent : header } )
206
- createEl ( 'th' , { text : 'Reporter' , parent : header } )
207
- createEl ( 'th' , { text : 'Assignee' , parent : header } )
208
- createEl ( 'abbr' , { text : 'P' , title : 'Priority' , parent : createEl ( 'th' , { parent : header } ) } )
209
- createEl ( 'th' , { text : 'Status' , parent : header } )
210
- // createEl('th', { text: 'Due Date', parent: header })
208
+ for ( const column of this . _settings . searchColumns ) {
209
+ // const name = column.type !== ESearchColumnsTypes.CUSTOM ? SEARCH_COLUMNS_DESCRIPTION[column.type] : column.customField
210
+ const name = SEARCH_COLUMNS_DESCRIPTION [ column . type ]
211
+ if ( column . compact ) {
212
+ createEl ( 'abbr' , { text : name [ 0 ] . toUpperCase ( ) , title : name , parent : createEl ( 'th' , { parent : header } ) } )
213
+ } else {
214
+ createEl ( 'th' , { text : name , parent : header } )
215
+ }
216
+ }
217
+ }
218
+
219
+ private renderSearchResultsTableBody ( table : HTMLElement , searchResults : IJiraSearchResults ) : void {
211
220
const tbody = createEl ( 'tbody' , { parent : table } )
212
221
for ( let issue of searchResults . issues ) {
213
222
issue = createProxy ( issue )
214
223
const row = createEl ( 'tr' , { parent : tbody } )
215
- createEl ( 'a' , { cls : 'no-wrap' , href : this . issueUrl ( issue . key ) , text : issue . key , parent : createEl ( 'td' , { parent : row } ) } )
216
- createEl ( 'td' , { text : issue . fields . summary , parent : row } )
217
- createEl ( 'img' , {
218
- attr : { src : issue . fields . issuetype . iconUrl , alt : issue . fields . issuetype . name } ,
219
- title : issue . fields . issuetype . name ,
220
- parent : createEl ( 'td' , { parent : row } )
221
- } )
222
- createEl ( 'td' , { text : dateToStr ( issue . fields . created ) , parent : row } )
223
- createEl ( 'td' , { text : dateToStr ( issue . fields . updated ) , parent : row } )
224
- createEl ( 'td' , { text : issue . fields . reporter . displayName , parent : row } )
225
- createEl ( 'td' , { text : issue . fields . assignee . displayName , parent : row } )
226
- createEl ( 'img' , {
227
- attr : { src : issue . fields . priority . iconUrl , alt : issue . fields . priority . name } ,
228
- title : issue . fields . priority . name ,
229
- parent : createEl ( 'td' , { parent : row } )
230
- } )
231
- const statusColor = JIRA_STATUS_COLOR_MAP [ issue . fields . status . statusCategory . colorName ] || 'is-light'
232
- createSpan ( { cls : `ji-tag no-wrap ${ statusColor } ` , text : issue . fields . status . name , title : issue . fields . status . description , parent : createEl ( 'td' , { parent : row } ) } )
224
+ for ( const column of this . _settings . searchColumns ) {
225
+ switch ( column . type ) {
226
+ case ESearchColumnsTypes . KEY :
227
+ createEl ( 'a' , {
228
+ cls : 'no-wrap' ,
229
+ href : this . issueUrl ( issue . key ) ,
230
+ text : column . compact ? '🔗' : issue . key ,
231
+ title : column . compact ? issue . key : '' ,
232
+ parent : createEl ( 'td' , { parent : row } )
233
+ } )
234
+ break
235
+ case ESearchColumnsTypes . SUMMARY :
236
+ if ( column . compact ) {
237
+ createEl ( 'td' , { text : issue . fields . summary . substring ( 0 , 20 ) , title : issue . fields . summary , parent : row } )
238
+ } else {
239
+ createEl ( 'td' , { text : issue . fields . summary , parent : row } )
240
+ }
241
+ break
242
+ case ESearchColumnsTypes . TYPE :
243
+ const typeCell = createEl ( 'td' , { parent : row } )
244
+ createEl ( 'img' , {
245
+ attr : { src : issue . fields . issuetype . iconUrl , alt : issue . fields . issuetype . name } ,
246
+ title : column . compact ? issue . fields . issuetype . name : '' ,
247
+ cls : 'letter-height' ,
248
+ parent : typeCell
249
+ } )
250
+ if ( ! column . compact ) {
251
+ createSpan ( { text : ' ' + issue . fields . issuetype . name , parent : typeCell } )
252
+ }
253
+ break
254
+ case ESearchColumnsTypes . CREATED :
255
+ if ( column . compact ) {
256
+ createEl ( 'td' , { text : '🕑' , title : dateToStr ( issue . fields . created ) , parent : row } )
257
+ } else {
258
+ createEl ( 'td' , { text : dateToStr ( issue . fields . created ) , parent : row } )
259
+ }
260
+ break
261
+ case ESearchColumnsTypes . UPDATED :
262
+ if ( column . compact ) {
263
+ createEl ( 'td' , { text : '🕑' , title : dateToStr ( issue . fields . updated ) , parent : row } )
264
+ } else {
265
+ createEl ( 'td' , { text : dateToStr ( issue . fields . updated ) , parent : row } )
266
+ }
267
+ break
268
+ case ESearchColumnsTypes . REPORTER :
269
+ const reporterName = issue . fields . reporter . displayName || ''
270
+ if ( column . compact ) {
271
+ createEl ( 'td' , { text : reporterName . split ( ' ' ) . last ( ) , title : reporterName , parent : row } )
272
+ } else {
273
+ createEl ( 'td' , { text : reporterName , parent : row } )
274
+ }
275
+ break
276
+ case ESearchColumnsTypes . ASSIGNEE :
277
+ const assigneeName = issue . fields . assignee . displayName || ''
278
+ if ( column . compact ) {
279
+ createEl ( 'td' , { text : assigneeName . split ( ' ' ) . last ( ) , title : assigneeName , parent : row } )
280
+ } else {
281
+ createEl ( 'td' , { text : assigneeName , parent : row } )
282
+ }
283
+ break
284
+ case ESearchColumnsTypes . PRIORITY :
285
+ const priorityCell = createEl ( 'td' , { parent : row } )
286
+ createEl ( 'img' , {
287
+ attr : { src : issue . fields . priority . iconUrl , alt : issue . fields . priority . name } ,
288
+ title : column . compact ? issue . fields . priority . name : '' ,
289
+ cls : 'letter-height' ,
290
+ parent : priorityCell
291
+ } )
292
+ if ( ! column . compact ) {
293
+ createSpan ( { text : ' ' + issue . fields . priority . name , parent : priorityCell } )
294
+ }
295
+ break
296
+ case ESearchColumnsTypes . STATUS :
297
+ const statusColor = JIRA_STATUS_COLOR_MAP [ issue . fields . status . statusCategory . colorName ] || 'is-light'
298
+ if ( column . compact ) {
299
+ createSpan ( { cls : `ji-tag no-wrap ${ statusColor } ` , text : issue . fields . status . name [ 0 ] . toUpperCase ( ) , title : issue . fields . status . name , parent : createEl ( 'td' , { parent : row } ) } )
300
+ } else {
301
+ createSpan ( { cls : `ji-tag no-wrap ${ statusColor } ` , text : issue . fields . status . name , title : issue . fields . status . description , parent : createEl ( 'td' , { parent : row } ) } )
302
+ }
303
+ break
304
+ // case ESearchColumnsTypes.CUSTOM:
305
+ // break
306
+ }
307
+ }
233
308
// createEl('td', { text: dateToStr(issue.fields.duedate), parent: row })
234
309
}
235
- const statistics = createSpan ( { cls : 'statistics' , text : `Total results: ${ searchResults . total . toString ( ) } - Last update: ${ this . _cache . getTime ( query ) } ` } )
236
- el . replaceChildren ( this . renderContainer ( [ table , statistics ] ) )
237
310
}
238
311
239
312
private renderSearchResultsList ( el : HTMLElement , searchResults : IJiraSearchResults ) : void {
0 commit comments