Skip to content

Commit d86dd86

Browse files
committed
Search columns customization #4
1 parent d500ad8 commit d86dd86

File tree

3 files changed

+122
-45
lines changed

3 files changed

+122
-45
lines changed

src/processor.ts

+104-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MarkdownPostProcessorContext } from "obsidian"
22
import { createProxy, IJiraIssue, IJiraSearchResults } from "./interfaces"
33
import { JiraClient } from "./jiraClient"
44
import { ObjectsCache } from "./objectsCache"
5-
import { ESearchResultsRenderingTypes, IJiraIssueSettings } from "./settings"
5+
import { ESearchColumnsTypes, ESearchResultsRenderingTypes, IJiraIssueSettings, SEARCH_COLUMNS_DESCRIPTION } from "./settings"
66

77
const COMMENT_REGEX = /^\s*#/
88
const ISSUE_REGEX = /^\s*([A-Z0-9]+-[0-9]+)\s*$/i
@@ -197,43 +197,116 @@ export class JiraIssueProcessor {
197197

198198
private renderSearchResultsTable(el: HTMLElement, query: string, searchResults: IJiraSearchResults): void {
199199
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 {
200207
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 {
211220
const tbody = createEl('tbody', { parent: table })
212221
for (let issue of searchResults.issues) {
213222
issue = createProxy(issue)
214223
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+
}
233308
// createEl('td', { text: dateToStr(issue.fields.duedate), parent: row })
234309
}
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]))
237310
}
238311

239312
private renderSearchResultsList(el: HTMLElement, searchResults: IJiraSearchResults): void {

src/settings.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export enum ESearchColumnsTypes {
3131
ASSIGNEE = 'ASSIGNEE',
3232
PRIORITY = 'PRIORITY',
3333
STATUS = 'STATUS',
34-
CUSTOM = 'CUSTOM',
34+
// CUSTOM = 'CUSTOM',
3535
}
36-
const SEARCH_COLUMNS_DESCRIPTION = {
36+
export const SEARCH_COLUMNS_DESCRIPTION = {
3737
[ESearchColumnsTypes.KEY]: 'Key',
3838
[ESearchColumnsTypes.SUMMARY]: 'Summary',
3939
[ESearchColumnsTypes.TYPE]: 'Type',
@@ -43,7 +43,7 @@ const SEARCH_COLUMNS_DESCRIPTION = {
4343
[ESearchColumnsTypes.ASSIGNEE]: 'Assignee',
4444
[ESearchColumnsTypes.PRIORITY]: 'Priority',
4545
[ESearchColumnsTypes.STATUS]: 'Status',
46-
[ESearchColumnsTypes.CUSTOM]: 'Custom',
46+
// [ESearchColumnsTypes.CUSTOM]: 'Custom',
4747
}
4848

4949
interface ISearchColumn {
@@ -241,16 +241,16 @@ export class JiraIssueSettingsTab extends PluginSettingTab {
241241
}).selectEl.addClass('flex-grow-1')
242242
)
243243

244-
if (column.type === ESearchColumnsTypes.CUSTOM) {
245-
setting.addText(text => text
246-
.setPlaceholder('Custom field name')
247-
.setValue(column.customField)
248-
.onChange(async value => {
249-
this._data.searchColumns[index].customField = value
250-
await this.saveSettings()
251-
}).inputEl.addClass('custom-field-text')
252-
)
253-
}
244+
// if (column.type === ESearchColumnsTypes.CUSTOM) {
245+
// setting.addText(text => text
246+
// .setPlaceholder('Custom field name')
247+
// .setValue(column.customField)
248+
// .onChange(async value => {
249+
// this._data.searchColumns[index].customField = value
250+
// await this.saveSettings()
251+
// }).inputEl.addClass('custom-field-text')
252+
// )
253+
// }
254254
setting.addExtraButton(button => button
255255
.setIcon(this._data.searchColumns[index].compact ? 'compress-glyph' : 'enlarge-glyph')
256256
.setTooltip(this._data.searchColumns[index].compact ? 'Compact' : 'Full width')

styles.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,12 @@ th {
321321
flex-grow: 1;
322322
max-width: none;
323323
}
324-
.setting-item-control input[type='text'].custom-field-text {
324+
.setting-item-control input[type="text"].custom-field-text {
325325
margin-left: 10px;
326326
height: 2.5em;
327327
border-radius: 8px;
328328
}
329+
330+
.letter-height {
331+
height: 1em;
332+
}

0 commit comments

Comments
 (0)