Skip to content

Commit

Permalink
feat: extract tags from task summary
Browse files Browse the repository at this point in the history
Signed-off-by: Raimund Schlüßler <[email protected]>
  • Loading branch information
raimund-schluessler committed Dec 30, 2023
1 parent c2fc5ac commit 02748bd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/store/storeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,33 @@ function searchSubTasks(task, searchQuery) {
})
}

/**

Check warning on line 452 in src/store/storeHelper.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @param "str" declaration
* Parses a string to extract tags and a summary
*
* @param {string} string The string
* @return {object} The object containing the parsed results
*/
function parseString(str) {
const matches = str.matchAll(/\s?#([^\s#]+)/g)
let summary = str
const tags = []
for (const match of matches) {
tags.push(match[1])
summary = summary.replace(match[0], '')
}
summary = summary.trim()
return {
summary,
tags,
}
}

export {
isTaskInList,
overdue,
isParentInList,
sort,
momentToICALTime,
searchSubTasks,
parseString,
}
8 changes: 6 additions & 2 deletions src/store/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import { Calendar } from './calendars.js'
import { findVTODObyUid } from './cdav-requests.js'
import { isParentInList, momentToICALTime } from './storeHelper.js'
import { isParentInList, momentToICALTime, parseString } from './storeHelper.js'
import SyncStatus from '../models/syncStatus.js'
import Task from '../models/task.js'

Expand All @@ -35,6 +35,7 @@ import moment from '@nextcloud/moment'
import ICAL from 'ical.js'
import Vue from 'vue'
import Vuex from 'vuex'
import { parse } from 'uuid'

Check failure on line 38 in src/store/tasks.js

View workflow job for this annotation

GitHub Actions / NPM lint

'parse' is defined but never used

Vue.use(Vuex)

Expand Down Expand Up @@ -703,8 +704,11 @@ const actions = {
}
const task = new Task('BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Nextcloud Tasks v' + appVersion + '\nEND:VCALENDAR', taskData.calendar)

const parsed = parseString(taskData.summary)

task.created = ICAL.Time.now()
task.summary = taskData.summary
task.summary = parsed.summary
task.tags = parsed.tags
task.hidesubtasks = 0
if (taskData.priority) {
task.priority = taskData.priority
Expand Down
32 changes: 30 additions & 2 deletions tests/javascript/unit/store/storeHelper.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sort } from '../../../../src/store/storeHelper.js'
import { sort, parseString } from '../../../../src/store/storeHelper.js'
import Task from '../../../../src/models/task.js'

import { loadICS } from '../../../assets/loadAsset.js'
Expand All @@ -14,7 +14,7 @@ const vCalendarNames = [

const tasks = vCalendarNames.map((vCalendar) => { return new Task(loadICS(vCalendar)) })

describe('storeHelper', () => {
describe('storeHelper - sort', () => {
'use strict'

it('Tests descending sort by due date.', () => {
Expand All @@ -31,3 +31,31 @@ describe('storeHelper', () => {
expect(receivedTasks).toEqual(expectedTasks)
})
})

describe('storeHelper - parseString', () => {
'use strict'

it('returns the whole summary if no delimiters are present', () => {
const summary = 'plain summary without special delimiters'
const result = parseString(summary)
expect(result).toEqual({ summary, tags: []})

Check failure on line 41 in tests/javascript/unit/store/storeHelper.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required before '}'
})

it('returns the summary and single tag found', () => {
const summary = 'summary and #tag'
const result = parseString(summary)
expect(result).toEqual({ summary: 'summary and', tags: ['tag']})

Check failure on line 47 in tests/javascript/unit/store/storeHelper.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required before '}'
})

it('returns the summary and multiple tags found', () => {
const summary = 'summary and #tag1 #tag2'
const result = parseString(summary)
expect(result).toEqual({ summary: 'summary and', tags: ['tag1', 'tag2']})

Check failure on line 53 in tests/javascript/unit/store/storeHelper.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required before '}'
})

it('returns the summary and multiple tags found in varying order', () => {
const summary = '#tag1 summary and #tag2 #tag3 more summary #tag4'
const result = parseString(summary)
expect(result).toEqual({ summary: 'summary and more summary', tags: ['tag1', 'tag2', 'tag3', 'tag4']})

Check failure on line 59 in tests/javascript/unit/store/storeHelper.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required before '}'
})
})

Check failure on line 61 in tests/javascript/unit/store/storeHelper.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Newline required at end of file but not found

0 comments on commit 02748bd

Please sign in to comment.