Skip to content

Commit

Permalink
Rename base64 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikVerheul committed Aug 5, 2024
1 parent cbaf797 commit f3b0701
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
14 changes: 7 additions & 7 deletions nodejs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ function bytesToBase64(bytes) {
}

// convert unicode string to base64 encoded ascii
function utoa(str) {
function uniTob64(str) {
return bytesToBase64(new TextEncoder().encode(str))
}

// convert base64 encoded ascii to unicode string
function atou(bytes) {
function b64ToUni(bytes) {
return new TextDecoder().decode(base64ToBytes(bytes))
}

Expand Down Expand Up @@ -98,9 +98,9 @@ function mkHtml(dbName, eventType, value, event, doc) {
}
switch (eventType) {
case "acceptanceEvent":
return mkHeader() + `<h3>The acceptance criteria changed from:</h3><p>${replaceEmpty(atou(value[0]))}</p> to <p>${replaceEmpty(atou(value[1]))}</p>` + mkFooter()
return mkHeader() + `<h3>The acceptance criteria changed from:</h3><p>${replaceEmpty(b64ToUni(value[0]))}</p> to <p>${replaceEmpty(b64ToUni(value[1]))}</p>` + mkFooter()
case "addCommentEvent":
return mkHeader() + `<h3>The user added a comment:</h3><p>${replaceEmpty(atou(value[0]))}</p>` + mkFooter()
return mkHeader() + `<h3>The user added a comment:</h3><p>${replaceEmpty(b64ToUni(value[0]))}</p>` + mkFooter()
case "addSprintIdsEvent":
{
let txt = `This ${getLevelText(dbName, value[0], value[1])} is assigned to sprint '${value[2]}'.`
Expand All @@ -110,7 +110,7 @@ function mkHtml(dbName, eventType, value, event, doc) {
case "cloneEvent":
return mkHeader() + `<h3>This ${getLevelText(dbName, value[0], value[1])} has been cloned as item of product '${value[2]}'.</h3>` + mkFooter()
case "commentToHistoryEvent":
return mkHeader() + `<h3>The user added comment:</h3><p>${replaceEmpty(atou(value[0]))}</p><h3>to the history of this item</h3>` + mkFooter()
return mkHeader() + `<h3>The user added comment:</h3><p>${replaceEmpty(b64ToUni(value[0]))}</p><h3>to the history of this item</h3>` + mkFooter()
case "conditionRemovedEvent":
{
let s
Expand All @@ -128,7 +128,7 @@ function mkHtml(dbName, eventType, value, event, doc) {
return mkHeader() + `<h3>${s}</h3>` + + mkFooter()
}
case "descriptionEvent":
return mkHeader() + `<h3>The description changed from:</h3><p>${replaceEmpty(atou(value[0]))}</p> to <p>${replaceEmpty(atou(value[1]))}</p>` + mkFooter()
return mkHeader() + `<h3>The description changed from:</h3><p>${replaceEmpty(b64ToUni(value[0]))}</p> to <p>${replaceEmpty(b64ToUni(value[1]))}</p>` + mkFooter()
case "undoBranchRemovalEvent":
return mkHeader() + `<h3>The ${this.getLevelText(value[9], value[10])} with title '${value[11]}' and ${value[1]} descendants are restored from removal.</h3>` + mkFooter()
case "newChildEvent":
Expand Down Expand Up @@ -157,7 +157,7 @@ function mkHtml(dbName, eventType, value, event, doc) {
case "removeStoryEvent":
return mkHeader() + `<h3>This ${getLevelText(dbName, value[0], value[1])} is removed from sprint '${value[2]}</h3>` + mkFooter()
case "replaceCommentEvent":
return mkHeader() + `<h3>The user changed his last comment:</h3><p>${replaceEmpty(atou(value[0]))}</p>` + mkFooter()
return mkHeader() + `<h3>The user changed his last comment:</h3><p>${replaceEmpty(b64ToUni(value[0]))}</p>` + mkFooter()
case "setConditionEvent":
if (value[2]) return mkHeader() + `<h3>The previous condition set for item '${value[1]} is undone'.</h3>` + mkFooter()
return mkHeader() + `<h3>This item is set to be conditional for item '${value[1]}'.</h3>` + mkFooter()
Expand Down
6 changes: 3 additions & 3 deletions src/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function bytesToBase64(bytes) {
}

// convert unicode string to base64 encoded ascii
export function utoa(str) {
export function uniTob64(str) {
return bytesToBase64(new TextEncoder().encode(str))
}

// convert base64 encoded ascii to unicode string
export function atou(bytes) {
export function b64ToUni(bytes) {
return new TextDecoder().decode(base64ToBytes(bytes))
}

Expand Down Expand Up @@ -185,4 +185,4 @@ export function isValidEmail(email) {
return re.test(email)
}

export default { utoa, atou, expandNode, collapseNode, showNode, hideNode, addToArray, createId, createLoadEventText, dedup, getLocationInfo, getSprintById, getSprintNameById, localTimeAndMilis, removeFromArray, isValidEmail }
export default { uniTob64, b64ToUni, expandNode, collapseNode, showNode, hideNode, addToArray, createId, createLoadEventText, dedup, getLocationInfo, getSprintById, getSprintNameById, localTimeAndMilis, removeFromArray, isValidEmail }
10 changes: 5 additions & 5 deletions src/components/views/common_context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SEV, STATE, MISC } from '../../constants.js'
import { utoa, createId } from '../../common_functions.js'
import { uniTob64, createId } from '../../common_functions.js'
import { authorization, utilities } from '../mixins/generic.js'
import store from '../../store/store.js'

Expand Down Expand Up @@ -157,8 +157,8 @@ const methods = {
conditionalFor: [],
title: newNode.title,
followers: [],
description: utoa(currentDoc.description),
acceptanceCriteria: utoa(currentDoc.acceptanceCriteria),
description: uniTob64(currentDoc.description),
acceptanceCriteria: uniTob64(currentDoc.acceptanceCriteria),
priority: newNode.data.priority,
comments: [{
ignoreEvent: 'comments initiated',
Expand Down Expand Up @@ -267,8 +267,8 @@ const methods = {
conditionalFor: [],
title: newNode.title,
followers: newNode.data.followers,
description: utoa(''),
acceptanceCriteria: newNode.level < this.TASKLEVEL ? utoa('<p>Please do not neglect</p>') : utoa('<p>See the acceptance criteria of the story/spike/defect.</p>'),
description: uniTob64(''),
acceptanceCriteria: newNode.level < this.TASKLEVEL ? uniTob64('<p>Please do not neglect</p>') : uniTob64('<p>See the acceptance criteria of the story/spike/defect.</p>'),
priority: newNode.data.priority,
comments: [{
ignoreEvent: 'comments initiated',
Expand Down
14 changes: 7 additions & 7 deletions src/components/views/common_listings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { utilities } from '../mixins/generic.js'
import { atou } from '../../common_functions.js'
import { b64ToUni } from '../../common_functions.js'
import store from '../../store/store.js'


Expand Down Expand Up @@ -203,7 +203,7 @@ const methods = {

/* Presentation methods */
mkAcceptanceEvent(value) {
return '<h6>The acceptance criteria of the item have changed:(from/to)<hr></h6>' + replaceEmpty(atou(value[0])) + '<hr>' + replaceEmpty(atou(value[1]))
return '<h6>The acceptance criteria of the item have changed:(from/to)<hr></h6>' + replaceEmpty(b64ToUni(value[0])) + '<hr>' + replaceEmpty(b64ToUni(value[1]))
},

mkAddSprintIdsEvent(value) {
Expand All @@ -221,7 +221,7 @@ const methods = {
},

mkCommentToHistoryEvent(value) {
return replaceEmpty(atou(value[0]))
return replaceEmpty(b64ToUni(value[0]))
},

mkConditionRemovedEvent(value) {
Expand Down Expand Up @@ -249,7 +249,7 @@ const methods = {
},

mkDescriptionEvent(value) {
return '<h6>The description of the item has changed:(from/to)<hr></h6>' + replaceEmpty(atou(value[0])) + '<hr>' + replaceEmpty(atou(value[1]))
return '<h6>The description of the item has changed:(from/to)<hr></h6>' + replaceEmpty(b64ToUni(value[0])) + '<hr>' + replaceEmpty(b64ToUni(value[1]))
},

mkImportToSprintEvent(value) {
Expand Down Expand Up @@ -369,7 +369,7 @@ const methods = {
},

mkComment(value) {
return replaceEmpty(atou(value[0]))
return replaceEmpty(b64ToUni(value[0]))
},

mkResetCommentsEvent(value) {
Expand Down Expand Up @@ -413,13 +413,13 @@ const methods = {

startEditMyComment(comment) {
this.commentObjToBeReplaced = comment
this.myLastCommentText = atou(this.getEventValue(comment))
this.myLastCommentText = b64ToUni(this.getEventValue(comment))
this.editMyComment = true
},

startEditMyHistComment(comment) {
this.commentObjToBeReplaced = comment
this.myLastHistCommentText = atou(this.getEventValue(comment))
this.myLastHistCommentText = b64ToUni(this.getEventValue(comment))
this.editMyHistComment = true
},

Expand Down
8 changes: 4 additions & 4 deletions src/store/modules/sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SEV, LEVEL, MISC } from '../../constants.js'
import { atou, getLocationInfo } from '../../common_functions.js'
import { b64ToUni, getLocationInfo } from '../../common_functions.js'
import globalAxios from 'axios'
var lastSeq = undefined
const SPECIAL_TEXT = true
Expand Down Expand Up @@ -243,7 +243,7 @@ const actions = {
}
break
case 'descriptionEvent':
commit('updateNodesAndCurrentDoc', { node, description: atou(doc.description), lastContentChange: doc.lastContentChange })
commit('updateNodesAndCurrentDoc', { node, description: b64ToUni(doc.description), lastContentChange: doc.lastContentChange })
showSyncMessage(`changed the description of`, SEV.INFO)
break
case 'nodeMovedEvent':
Expand Down Expand Up @@ -279,7 +279,7 @@ const actions = {
// process events for non requirement area items
switch (histEvent) {
case 'acceptanceEvent':
commit('updateNodesAndCurrentDoc', { node, acceptanceCriteria: atou(doc.acceptanceCriteria), lastContentChange: doc.lastContentChange })
commit('updateNodesAndCurrentDoc', { node, acceptanceCriteria: b64ToUni(doc.acceptanceCriteria), lastContentChange: doc.lastContentChange })
showSyncMessage(`changed the acceptance criteria for`, SEV.INFO)
break
case 'addSprintIdsEvent':
Expand Down Expand Up @@ -312,7 +312,7 @@ const actions = {
showSyncMessage(`removed a condition for`, SEV.INFO)
break
case 'descriptionEvent':
commit('updateNodesAndCurrentDoc', { node, description: atou(doc.description), lastContentChange: doc.lastContentChange })
commit('updateNodesAndCurrentDoc', { node, description: b64ToUni(doc.description), lastContentChange: doc.lastContentChange })
showSyncMessage(`changed the description of`, SEV.INFO)
break
case 'itemToNewTeamEvent':
Expand Down
22 changes: 11 additions & 11 deletions src/store/modules/update.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SEV, STATE, LEVEL } from '../../constants.js'
import { utoa, atou } from '../../common_functions.js'
import { uniTob64, b64ToUni } from '../../common_functions.js'
import globalAxios from 'axios'
// IMPORTANT: all updates on the backlogitem documents must add history in order for the changes feed to work properly (if omitted the previous event will be processed again)
// Save the history, to trigger the distribution to other online users, when all other database updates are done.
Expand Down Expand Up @@ -720,9 +720,9 @@ const actions = {
}).then(res => {
const tmpDoc = res.data
// decode from base64
const oldDescription = atou(tmpDoc.description)
const oldDescription = b64ToUni(tmpDoc.description)
// encode to base64
const newEncodedDescription = utoa(payload.newDescription)
const newEncodedDescription = uniTob64(payload.newDescription)
const newHist = {
descriptionEvent: [tmpDoc.description, newEncodedDescription],
by: rootState.userData.user,
Expand Down Expand Up @@ -784,9 +784,9 @@ const actions = {
}).then(res => {
const tmpDoc = res.data
// decode from base64
const oldAcceptance = atou(tmpDoc.acceptanceCriteria)
const oldAcceptance = b64ToUni(tmpDoc.acceptanceCriteria)
// encode to base64
const newEncodedAcceptance = utoa(payload.newAcceptance)
const newEncodedAcceptance = uniTob64(payload.newAcceptance)
const newHist = {
acceptanceEvent: [tmpDoc.acceptanceCriteria, newEncodedAcceptance],
by: rootState.userData.user,
Expand Down Expand Up @@ -847,7 +847,7 @@ const actions = {
}).then((res) => {
const tmpDoc = res.data
const newComment = {
addCommentEvent: [utoa(payload.comment)],
addCommentEvent: [uniTob64(payload.comment)],
by: rootState.userData.user,
email: rootState.userData.email,
timestamp: Date.now(),
Expand All @@ -857,7 +857,7 @@ const actions = {
tmpDoc.lastChange = payload.timestamp

const newHist = {
addCommentEvent: [utoa(payload.comment)],
addCommentEvent: [uniTob64(payload.comment)],
by: rootState.userData.user,
email: rootState.userData.email,
timestamp: Date.now(),
Expand Down Expand Up @@ -897,15 +897,15 @@ const actions = {
for (let i = 0; i < tmpDoc.comments.length; i++) {
const uneditedCommentObj = tmpDoc.comments[i]
if (Object.keys(uneditedCommentObj)[0] === 'addCommentEvent' && uneditedCommentObj.timestamp === payload.commentObjToBeReplaced.timestamp) {
tmpDoc.comments[i].addCommentEvent = [utoa(payload.editedCommentText)]
tmpDoc.comments[i].addCommentEvent = [uniTob64(payload.editedCommentText)]
tmpDoc.comments[i].timestamp = Date.now()
couldReplace = true
break
}
}
if (couldReplace) {
const newHist = {
replaceCommentEvent: [utoa(payload.editedCommentText)],
replaceCommentEvent: [uniTob64(payload.editedCommentText)],
by: rootState.userData.user,
email: rootState.userData.email,
timestamp: Date.now(),
Expand Down Expand Up @@ -954,7 +954,7 @@ const actions = {
if (Object.keys(tmpDoc.history[i])[0] === 'commentToHistoryEvent') {
const uneditedCommentObj = tmpDoc.history[i]
if (uneditedCommentObj.timestamp === payload.commentObjToBeReplaced.timestamp) {
tmpDoc.history[i].commentToHistoryEvent = [utoa(payload.editedCommentText)]
tmpDoc.history[i].commentToHistoryEvent = [uniTob64(payload.editedCommentText)]
tmpDoc.history[i].timestamp = Date.now()
couldReplace = true
break
Expand Down Expand Up @@ -998,7 +998,7 @@ const actions = {
}).then(res => {
const tmpDoc = res.data
const newHist = {
commentToHistoryEvent: [utoa(payload.comment)],
commentToHistoryEvent: [uniTob64(payload.comment)],
by: rootState.userData.user,
email: rootState.userData.email,
timestamp: Date.now(),
Expand Down
6 changes: 3 additions & 3 deletions src/store/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStore } from 'vuex'
import globalAxios from 'axios'
import { atou, expandNode, collapseNode, addToArray, removeFromArray } from '../common_functions.js'
import { b64ToUni, expandNode, collapseNode, addToArray, removeFromArray } from '../common_functions.js'
// IMPORTANT: all updates on the backlogitem documents must add history in order for the changes feed to work properly (if omitted the previous event will be processed again)
// Save the history, to trigger the distribution to other online users, when all other database updates are done.
import { SEV, LEVEL, MISC } from '../constants.js'
Expand Down Expand Up @@ -896,8 +896,8 @@ const store = createStore({

if (payload.newDoc) {
// decode from base64 + replace the encoded data
payload.newDoc.description = atou(payload.newDoc.description)
payload.newDoc.acceptanceCriteria = atou(payload.newDoc.acceptanceCriteria)
payload.newDoc.description = b64ToUni(payload.newDoc.description)
payload.newDoc.acceptanceCriteria = b64ToUni(payload.newDoc.acceptanceCriteria)
// replace the currently loaded document
state.currentDoc = cleanHistory(payload.newDoc)
}
Expand Down

0 comments on commit f3b0701

Please sign in to comment.