From e27872ddc38fa5f4a1ed7e9af1f3d5f804efb4c4 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Fri, 19 May 2017 18:50:39 +0200 Subject: [PATCH] added two more scripts --- note-from-bitrix-task/info.json | 9 ++ .../note-from-bitrix-task.qml | 127 ++++++++++++++++++ note-from-jira-issue/info.json | 9 ++ note-from-jira-issue/note-from-jira-issue.qml | 108 +++++++++++++++ 4 files changed, 253 insertions(+) create mode 100644 note-from-bitrix-task/info.json create mode 100644 note-from-bitrix-task/note-from-bitrix-task.qml create mode 100644 note-from-jira-issue/info.json create mode 100644 note-from-jira-issue/note-from-jira-issue.qml diff --git a/note-from-bitrix-task/info.json b/note-from-bitrix-task/info.json new file mode 100644 index 0000000..c6bbc5c --- /dev/null +++ b/note-from-bitrix-task/info.json @@ -0,0 +1,9 @@ +{ + "name": "Note from Bitrix24 task", + "identifier": "note-from-bitrix-task", + "script": "note-from-bitrix-task.qml", + "authors": ["@pbek"], + "version": "0.0.1", + "minAppVersion": "17.05.6", + "description" : "This script creates a menu item and a button that parses the text that was copied from a task webpage of the webservice Bitrix24 and creates a new note with a headline, the link to the task and the description." +} diff --git a/note-from-bitrix-task/note-from-bitrix-task.qml b/note-from-bitrix-task/note-from-bitrix-task.qml new file mode 100644 index 0000000..f9dc73b --- /dev/null +++ b/note-from-bitrix-task/note-from-bitrix-task.qml @@ -0,0 +1,127 @@ +import QtQml 2.0 +import com.qownnotes.noteapi 1.0 + +/** + * This script creates a menu item and a button that parses the text that was copied + * from a task webpage of the webservice bitrix24 and creates a new note with a headline, + * the link to the task and the description + */ +QtObject { + /** + * Initializes the custom action + */ + function init() { + // create a menu entry "New Bitrix note" with a button and a freedesktop theme icon + script.registerCustomAction("newBitrixTaskNote", "New Bitrix task note", "Bitrix", "task-new"); + } + + /** + * This function is invoked when a custom action is triggered + * in the menu or via button + * + * @param identifier string the identifier defined in registerCustomAction + */ + function customActionInvoked(identifier) { + switch (identifier) { + // create a new note from a Bitrix task webpage text in the clipboard + // like from https://yourname.bitrix24.com/workgroups/group/10/tasks/task/view/150/ + case "newBitrixTaskNote": + // get the text that is currently in the clipboard + var html = script.clipboard(true); + +// script.log(html); + + // https://regex101.com is your friend +// var headlineRegExp = /(.+?)<\/span>/im; + var headlineRegExp = /(.+?)<\/?span/im; + var headlineMatch = headlineRegExp.exec(html); + var headline = headlineMatch !== null ? headlineMatch[1] : ""; + // remove the "aufgabe" text and all "/" + headline = headline.replace("(aufgabe #", "(#").replace(/\s*\//igm, ""); + + if (headline == "") { + script.informationMessageBox("No Bitrix task headline was found!", "Bitrix task note"); + return; + } + + // add the task id to the headline + var taskIdRegExp = /
Aufgabe #(\d+)/im; + var taskIdMatch = taskIdRegExp.exec(html); + if (taskIdMatch !== null) { + headline += " (#" + taskIdMatch[1] + ")"; + } + + var descriptionRegExp = /(.+?)<\/div>/im; + var descriptionMatch = descriptionRegExp.exec(html); + var description = descriptionMatch !== null ? descriptionMatch[1] : ""; + + // replace links +// description = description.replace(/(.+?)<\/a>/gim, "[$2]($1)"); + description = description.replace(/(.+?)<\/a>/gim, "<$1>"); + + // transform html breaks to \n and remove all other tags + description = description.replace(//gim, "\n").replace(/<.+?>/gim, ""); + +// var urlRegExp = /