From 3cc622876c39ec7e4aef259ffb0ba9810aa56bed Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Wed, 14 Nov 2018 20:39:42 -0300 Subject: [PATCH 1/4] Adds mentions-parser lib app, used to parse ticket numbers preceded by a hashtag and transform them to links --- client/src/lib-app/mentions-parser.js | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 client/src/lib-app/mentions-parser.js diff --git a/client/src/lib-app/mentions-parser.js b/client/src/lib-app/mentions-parser.js new file mode 100644 index 00000000..81579c57 --- /dev/null +++ b/client/src/lib-app/mentions-parser.js @@ -0,0 +1,53 @@ +const PARSING_TEXT = 0; +const PARSING_MENTION = 1; + +class MentionsParser { + + parse(text) { + let parsingLink = false; + let parsingType = PARSING_TEXT; + let parsingSegment = ''; + let ans = ''; + + for(let index = 0; index < text.length; ++index){ + let character = text[index]; + + if(character == '#'){ + ans += this.compileSegment(parsingSegment, parsingType); + + parsingLink = true; + parsingType = PARSING_MENTION; + parsingSegment = ''; + } else if(!this.isAlphanumeric(character) && parsingLink){ + ans += this.compileSegment(parsingSegment, parsingType); + + parsingLink = false; + parsingType = PARSING_TEXT; + parsingSegment = character; + } else { + parsingSegment += character; + } + } + + ans += this.compileSegment(parsingSegment, parsingType); + + return ans; + } + + isAlphanumeric(string){ + return /[a-zA-Z0-9]/.test(string); + } + + compileSegment(segment, parsingType){ + switch(parsingType){ + case PARSING_TEXT: + return segment; + case PARSING_MENTION: + return '#' + segment + ''; + default: + return ''; + } + } +}; + +export default new MentionsParser; From e8c1ffeea76646cb8ace9daefaa97aee25f8f919 Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Thu, 15 Nov 2018 10:05:39 -0300 Subject: [PATCH 2/4] Adds parsing of mentions in articles from the admin panel --- .../src/app/admin/panel/articles/admin-panel-view-article.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/app/admin/panel/articles/admin-panel-view-article.js b/client/src/app/admin/panel/articles/admin-panel-view-article.js index d0d4fd98..bd97b333 100644 --- a/client/src/app/admin/panel/articles/admin-panel-view-article.js +++ b/client/src/app/admin/panel/articles/admin-panel-view-article.js @@ -7,6 +7,7 @@ import ArticlesActions from 'actions/articles-actions'; import SessionStore from 'lib-app/session-store'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; +import MentionsParser from 'lib-app/mentions-parser'; import DateTransformer from 'lib-core/date-transformer'; import AreYouSure from 'app-components/are-you-sure'; @@ -76,7 +77,7 @@ class AdminPanelViewArticle extends React.Component {
-
+
{i18n('LAST_EDITED_IN', {date: DateTransformer.transformToString(article.lastEdited)})} From b56ff24a7d1aaa6f5acac594b6a35861e1e884a3 Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Sat, 17 Nov 2018 12:21:07 -0300 Subject: [PATCH 3/4] Parses text from the content of a ticket to add links to mentioned tickets --- client/src/app-components/ticket-viewer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index 79cf0048..cafe0b0e 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -7,6 +7,7 @@ import AdminDataActions from 'actions/admin-data-actions'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; import SessionStore from 'lib-app/session-store'; +import MentionsParser from 'lib-app/mentions-parser'; import TicketEvent from 'app-components/ticket-event'; import AreYouSure from 'app-components/are-you-sure'; @@ -73,7 +74,7 @@ class TicketViewer extends React.Component {
{this.props.editable ? this.renderEditableHeaders() : this.renderHeaders()}
- +
{ticket.events && ticket.events.map(this.renderTicketEvent.bind(this))} From e1dffaef1694b6427c52b9f99e88e837a99a7cf7 Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Sat, 17 Nov 2018 12:30:52 -0300 Subject: [PATCH 4/4] Parses ticket comments to create links for mentioned tickets --- client/src/app-components/ticket-viewer.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index cafe0b0e..8429489b 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -207,6 +207,9 @@ class TicketViewer extends React.Component { } renderTicketEvent(options, index) { + if (this.props.userStaff) { + options.content = MentionsParser.parse(options.content); + } return ( );