Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor editor #371

Open
wants to merge 110 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
94c7b22
Merge pull request #253 from harena-lab/development
santanche Sep 29, 2020
7c137cf
Merge pull request #256 from harena-lab/development
santanche Oct 1, 2020
7c65ae9
Merge pull request #257 from harena-lab/development
santanche Oct 1, 2020
c8b37b1
Merge pull request #258 from harena-lab/development
santanche Oct 1, 2020
b89ef10
Merge pull request #259 from harena-lab/development
santanche Oct 1, 2020
42e6524
Merge pull request #260 from harena-lab/development
HeitorMatt Oct 2, 2020
03ff1b7
Merge pull request #261 from harena-lab/development
santanche Oct 6, 2020
699f06c
Merge pull request #262 from harena-lab/development
HeitorMatt Oct 18, 2020
cd2b408
Merge pull request #263 from harena-lab/development
santanche Oct 19, 2020
82724a0
Merge pull request #265 from harena-lab/development
HeitorMatt Oct 26, 2020
2ea499b
Merge pull request #266 from harena-lab/development
HeitorMatt Oct 26, 2020
1573d47
Update README.md
HeitorMatt Oct 28, 2020
e592126
Merge pull request #268 from harena-lab/development
HeitorMatt Nov 3, 2020
6d09bda
Merge pull request #272 from harena-lab/development
HeitorMatt Feb 8, 2021
e27e0a1
Merge pull request #274 from harena-lab/development
HeitorMatt Feb 17, 2021
a1144a0
Merge pull request #275 from harena-lab/development
HeitorMatt Feb 21, 2021
7b67b18
Merge pull request #276 from harena-lab/development
HeitorMatt Apr 27, 2021
6afefed
Merge pull request #279 from harena-lab/development
HeitorMatt Apr 29, 2021
68d31a0
Bump rexml from 3.2.4 to 3.2.5
dependabot[bot] Apr 30, 2021
9343226
Bump nokogiri from 1.10.10 to 1.11.5
dependabot[bot] May 20, 2021
5a66659
Create LICENSE
HeitorMatt Jun 14, 2021
aa343e5
Merge pull request #281 from harena-lab/dependabot/bundler/nokogiri-1…
santanche Jun 17, 2021
1088fab
Merge pull request #280 from harena-lab/dependabot/bundler/rexml-3.2.5
santanche Jun 17, 2021
887f4a3
Bump addressable from 2.7.0 to 2.8.0
dependabot[bot] Jul 13, 2021
f062a13
Merge pull request #284 from harena-lab/development
HeitorMatt Jul 21, 2021
9cdeaab
Merge pull request #283 from harena-lab/dependabot/bundler/addressabl…
HeitorMatt Aug 5, 2021
cacef4a
Merge pull request #286 from harena-lab/development
HeitorMatt Aug 5, 2021
78c18c5
Merge pull request #287 from harena-lab/development
santanche Aug 11, 2021
ce09ba1
Merge pull request #288 from harena-lab/development
HeitorMatt Aug 13, 2021
844a68f
Bump nokogiri from 1.11.5 to 1.12.5
dependabot[bot] Sep 28, 2021
0534314
Merge pull request #291 from harena-lab/development
santanche Oct 13, 2021
a33f3f4
Bump kramdown from 2.3.0 to 2.3.1
dependabot[bot] Oct 13, 2021
ee92ad3
Merge pull request #293 from harena-lab/development
santanche Oct 28, 2021
e6c7bbf
Merge pull request #294 from harena-lab/development
santanche Nov 6, 2021
e50d257
Merge pull request #295 from harena-lab/development
santanche Nov 10, 2021
b1bb4ba
Merge pull request #296 from harena-lab/development
santanche Nov 10, 2021
85e7faf
Merge pull request #298 from harena-lab/development
santanche Nov 16, 2021
3d6b57e
Merge pull request #299 from harena-lab/development
santanche Nov 23, 2021
d4260e8
Merge pull request #300 from harena-lab/development
HeitorMatt Nov 24, 2021
6ab4301
Merge pull request #301 from harena-lab/development
santanche Nov 30, 2021
19121df
Merge pull request #302 from harena-lab/development
santanche Dec 2, 2021
b6f3c32
Merge pull request #303 from harena-lab/development
santanche Dec 2, 2021
0d822b4
Merge pull request #304 from harena-lab/development
santanche Dec 3, 2021
071fbb3
Merge pull request #305 from harena-lab/development
santanche Dec 6, 2021
7e1b778
Merge pull request #306 from harena-lab/development
santanche Dec 6, 2021
443654a
Merge pull request #307 from harena-lab/development
santanche Dec 8, 2021
67c86f0
Merge pull request #308 from harena-lab/development
santanche Dec 9, 2021
f44be68
Merge pull request #309 from harena-lab/development
santanche Dec 10, 2021
e3bed11
Merge pull request #310 from harena-lab/development
santanche Dec 13, 2021
20080e7
Merge pull request #311 from harena-lab/development
santanche Dec 13, 2021
590c36b
Merge pull request #312 from harena-lab/development
santanche Dec 13, 2021
5c52d70
Merge pull request #313 from harena-lab/development
santanche Dec 14, 2021
61a2f9a
Merge pull request #314 from harena-lab/development
santanche Dec 17, 2021
37c3791
Merge pull request #315 from harena-lab/development
santanche Dec 21, 2021
24f5eca
Merge pull request #316 from harena-lab/development
santanche Dec 22, 2021
fc16ec6
Merge pull request #317 from harena-lab/development
santanche Dec 22, 2021
0451050
Merge pull request #318 from harena-lab/development
santanche Dec 22, 2021
53be0eb
Merge pull request #319 from harena-lab/development
santanche Dec 22, 2021
57a0a3d
Merge pull request #320 from harena-lab/development
santanche Dec 23, 2021
59ff5d0
Merge pull request #321 from harena-lab/development
santanche Dec 23, 2021
0ee2e9a
Merge pull request #322 from harena-lab/development
santanche Jan 7, 2022
d9b6007
Merge pull request #323 from harena-lab/development
santanche Jan 8, 2022
fa3a10a
Merge pull request #324 from harena-lab/development
santanche Jan 20, 2022
c8c8160
Merge pull request #325 from harena-lab/development
santanche Jan 25, 2022
e73c6df
Merge pull request #326 from harena-lab/development
santanche Jan 25, 2022
1211553
Merge pull request #327 from harena-lab/development
santanche Jan 25, 2022
094846d
Merge pull request #328 from harena-lab/development
santanche Jan 31, 2022
4211dd6
Merge pull request #329 from harena-lab/development
santanche Jan 31, 2022
7dee17e
Merge pull request #330 from harena-lab/development
santanche Feb 1, 2022
bdc01ad
Merge pull request #331 from harena-lab/development
santanche Feb 1, 2022
ad70d43
Merge pull request #332 from harena-lab/development
santanche Feb 1, 2022
06b493b
Merge pull request #333 from harena-lab/development
santanche Feb 1, 2022
6777683
Merge pull request #334 from harena-lab/development
santanche Feb 1, 2022
d3fc024
Merge pull request #335 from harena-lab/development
santanche Feb 1, 2022
21500a4
Merge pull request #292 from harena-lab/dependabot/bundler/kramdown-2…
HeitorMatt Feb 3, 2022
143c84a
Merge pull request #290 from harena-lab/dependabot/bundler/nokogiri-1…
HeitorMatt Feb 3, 2022
e53f76f
Merge pull request #337 from harena-lab/development
santanche Feb 3, 2022
230c9ec
Merge pull request #338 from harena-lab/development
santanche Feb 3, 2022
9e8acaf
Merge pull request #339 from harena-lab/development
santanche Feb 4, 2022
c26a0f0
Merge pull request #340 from harena-lab/development
santanche Feb 7, 2022
bafe9bb
Merge pull request #341 from harena-lab/development
santanche Feb 7, 2022
d12153a
Merge pull request #342 from harena-lab/development
santanche Feb 7, 2022
fb83be6
Merge pull request #343 from harena-lab/development
santanche Feb 10, 2022
b69ebe6
Merge pull request #344 from harena-lab/development
santanche Feb 12, 2022
b7da310
Merge pull request #346 from harena-lab/development
santanche Mar 15, 2022
802bc8c
Merge pull request #347 from harena-lab/development
santanche Mar 15, 2022
dae4e90
Merge pull request #348 from harena-lab/development
santanche Mar 16, 2022
3821d6a
Merge pull request #349 from harena-lab/development
santanche Mar 28, 2022
beeb0f4
Merge pull request #350 from harena-lab/development
santanche Mar 28, 2022
9e58cfc
Merge pull request #351 from harena-lab/development
santanche Mar 31, 2022
a95be3f
Merge pull request #352 from harena-lab/development
santanche Mar 31, 2022
457984c
Merge pull request #353 from harena-lab/development
santanche Apr 1, 2022
5d79c4f
initial commit
Bervcosta May 18, 2022
fde55ab
mergin
Bervcosta May 18, 2022
f02bcd4
mergin development
Bervcosta May 18, 2022
e621b34
Merge branch 'development' of https://github.com/datasci4health/haren…
Bervcosta May 25, 2022
b1ec86c
refactored for undo redo on sidepanel
Bervcosta Jun 29, 2022
0a1deb5
refactored for undo redo on sidepanel
Bervcosta Jun 29, 2022
e5715b9
finished implementation
Bervcosta Jul 26, 2022
c8dae49
Merge branch 'development' of https://github.com/datasci4health/haren…
Bervcosta Jul 26, 2022
27296ce
Merge branch 'development' into feature/refactor-editor
Bervcosta Jul 26, 2022
73095e3
updates
Bervcosta Jul 26, 2022
c68ae53
reverting gemfile.lock
Bervcosta Jul 26, 2022
cd2a0dc
revertin index cell
Bervcosta Jul 26, 2022
3d429d1
reverting unescessary changes
Bervcosta Jul 26, 2022
8be8d22
reverting unescessary changes
Bervcosta Jul 26, 2022
33dc8f9
reverting unescessary changes
Bervcosta Jul 26, 2022
a6e8e4a
reverting unescessary changes
Bervcosta Jul 26, 2022
fd13c91
reverting unescessary changes
Bervcosta Jul 26, 2022
14b7c07
reverting unescessary changes
Bervcosta Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Harena is available at https://harena.ds4h.org/.
<!-- platform that includes: authoring environment, player engine and the Versum narrative scripting language translator. -->

<!--
## Table of Contents
## Table of Contents

* [Getting Started](#getting-started)
* [Option 1: Access our instance running at cloud](#option-1-access-our-instance-running-at-cloud)
Expand Down
8 changes: 7 additions & 1 deletion src/adonisjs/public/author/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@
<script src="/translator/translator.js"></script>
<script src="/translator/item-templates.js"></script>

<script src="/dccs/edit/local-storage-stack.js"></script>
<script src="/dccs/edit/action-deserializer.js"></script>
<script src="/dccs/edit/command-manager.js"></script>
<script src="/dccs/edit/properties.js"></script>
<script src="/dccs/edit/action-apply-properties.js"></script>
<script src="/dccs/edit/upload-adapter.js"></script>
<script src="/dccs/edit/inplace-editor.js"></script>
<script src="/dccs/edit/inplace-plain-editor.js"></script>
Expand Down Expand Up @@ -347,6 +351,9 @@ <h6 style="color:#808080;">Created by {{author_grade}}: {{username}} ({{institut
</button>


<dcc-button xstyle="in" topic="properties/undo/details" label="UNDO"></dcc-button>
<dcc-button xstyle="in" topic="properties/redo/details" label="REDO"></dcc-button>

<div id="advanced-mode" style="display:none">
<dcc-button topic="control/case/markdown" label="MARKDOWN" xstyle="in"></dcc-button>
</div>
Expand Down Expand Up @@ -431,7 +438,6 @@ <h6 style="color:#808080;">Created by {{author_grade}}: {{username}} ({{institut
<div id="properties-panel" class="styp-properties-panel"></div>
<div id="properties-buttons">
<dcc-button xstyle="in" topic="properties/apply/details" label="APPLY"></dcc-button>
<dcc-button xstyle="in" topic="properties/undo/details" label="UNDO"></dcc-button>
<!--
<div class="control-button"><dcc-button xstyle="in" topic="control/element/selected/up" label="Element Up" image="icons/icon-move-up.svg"></dcc-button></div>
<div class="control-button"><dcc-button xstyle="in" topic="control/element/selected/down" label="Element Down" image="icons/icon-move-down.svg"></dcc-button></div>
Expand Down
32 changes: 24 additions & 8 deletions src/adonisjs/public/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ class AuthorManager {

this._caseModified = false

window.onbeforeunload = function () {
return (this._caseModified)
? 'If you leave this page you will lose your unsaved changes.' : null
}
// Function that runs when the user attempts to leave the page, making the user confirm before leaving
// To use this uncomment the next two lines and code and the tryHalt function.
// this.tryHalt = this.tryHalt.bind(this)
// window.onbeforeunload = this.tryHalt

this.commandManager = new CommandManager('caseEditor', this)
}

/* async tryHalt () {
try {
if (this._caseModified)
Tracker.caseTryHalt(pPlay.userid, pPlay.caseid, pPlay.running.runningId)
} catch (e) {
console.log('=== error on halt')
console.log(e)
}
return ''
}
*/

/* <TODO>
A commom code for shared functionalities between player and author
******/
Expand Down Expand Up @@ -261,6 +275,8 @@ class AuthorManager {
async caseLoadSelect () {
const saved = await this.saveChangedCase()

this.commandManager.clear()

const cases = await MessageBus.i.request('data/case/*/list', null, null, true)
// {user: this._userid});

Expand Down Expand Up @@ -298,7 +314,7 @@ class AuthorManager {
*/
async caseNew (template) {
this._temporaryCase = true

this.commandManager.clear()
// await this._themeSelect();
// let template = await this._templateSelect("case");

Expand Down Expand Up @@ -814,7 +830,7 @@ class AuthorManager {
console.log(topic)
console.log(message)

await Properties.s.closePreviousProperties()
await Properties.s.closePreviousProperties(message._selectedByAction)

const dccId = MessageBus.extractLevel(topic, 3)

Expand Down Expand Up @@ -845,9 +861,9 @@ class AuthorManager {
dcc = inDCC
}
parentDCC.edit(role)

Properties.s.editElementProperties(
this._knots, this._knotSelected, el, dcc, role, message.buttonType)
this._knots, this._knotSelected, el, dcc, role, message.buttonType, message.presentationId, dccId, this.commandManager)
}
}

Expand Down
66 changes: 66 additions & 0 deletions src/adonisjs/public/dccs/edit/action-apply-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class ApplyPropertiesAction{
//Action that implements element edit operations.

constructor(knotId, el, newObjProperties, oldObjProperties = null, dccId, role, buttonType, presentationId){
this._oldObjProperties = oldObjProperties
this._objProperties = null
this.el = el
this._newObjProperties = JSON.parse(JSON.stringify(newObjProperties))
this.type = 'ApplyProperties'
this.knotId = knotId
this._dccId = dccId
this._role = role
this._buttonType = buttonType
this._presentationId = presentationId
}

async execute(knots){
//Get Object Properties and clone it into oldObjProperties for later use
this._objProperties = knots[this.knotId].content[this.el]
this._oldObjProperties = JSON.parse(JSON.stringify(this._objProperties))

//Update Object Properties,Markdown and view
knots[this.knotId].content[this.el] = this._newObjProperties
Translator.instance.updateElementMarkdown(this._newObjProperties)
await MessageBus.i.request('control/knot/update', null, null, true)
}


async undo(knots){
//Restore object to oldObjProperties
knots[this.knotId].content[this.el] = this._oldObjProperties
this._objProperties = knots[this.knotId].content[this.el]
this._objProperties._modified = true
await MessageBus.i.request('control/knot/update', null, null, true)
}

selectElement(){
//Create a element selected message to change the selected element upon undo/redo actions
let topic = 'control/element/' + this._dccId + '/selected'

let message = {}
message._selectedByAction = true
if (this._role != null){
message.role = this._role
}
if (this._buttonType != null){
message.buttonType = this._buttonType
}
if (this._presentationId != null){
message.presentationId = this._presentationId
}

MessageBus.i.publish(topic, message)
}

serialize(action){
action.type = this.type
return JSON.stringify(action)
}

static deserialize(properties){
return new ApplyPropertiesAction(properties.knotId, properties.el, properties._newObjProperties, properties._oldObjProperties,
properties._dccId,properties._role, properties._buttonType, properties.presentationId)
}

}
11 changes: 11 additions & 0 deletions src/adonisjs/public/dccs/edit/action-deserializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ActionDeserializer{
static deserialize(action){
let properties = JSON.parse(action)
switch (properties.type) {
case 'ApplyProperties':
action = ApplyPropertiesAction.deserialize(properties)
break
}
return action
}
}
51 changes: 51 additions & 0 deletions src/adonisjs/public/dccs/edit/command-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class CommandManager{
//This Class is resposible for calling and managing actions. The Undo/Redo feature is here implemented by using the LocalStorageStack class to controll the
//undo and redo stacks so that the actions are stored in the brower local memory of the users computer and can later be retrieved.
constructor (editorName, author) {
//Create stacks and instatiate author
this._undoStack = new LocalStorageStack(editorName + 'UndoStack')
this._redoStack = new LocalStorageStack(editorName + 'RedoStack')
this._author = author
};

execute(action) {
//Call the execute item, push the action to the undo stack and clear the redo stack
this.knots = this._author._compiledCase.knots
action.execute(this.knots)
this._undoStack.push(action.serialize(action))
this._redoStack.clear()
}

undo(){
//Get the top item from the undo stack, add it on the redo stack, select the element and undo the action.
this.knots = this._author._compiledCase.knots
if(this._undoStack.length > 0){
let action = this._undoStack.pop()
this._redoStack.push(action)
action = ActionDeserializer.deserialize(action)
action.selectElement()
action.undo(this.knots)
}
}

redo(){
//Get the top action from the redo stack, add it to the undo stack, select the element and execute the action.
this.knots = this._author._compiledCase.knots
if(this._redoStack.length > 0){
let action = this._redoStack.pop()
this._undoStack.push(action)
action = ActionDeserializer.deserialize(action)
action.selectElement()
action.execute(this.knots)
}
}

clear(){
//Clear stacks and pointers to them.
this._undoStack.clear()
this._redoStack.clear()
this._undoStack = null
this._redoStack = null
}

}
8 changes: 4 additions & 4 deletions src/adonisjs/public/dccs/edit/inplace-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class EditDCC {
return ep
}

async handleConfirm () {
await this._handleEditorAction('confirm')
async handleConfirm (selectedByAction) {
await this._handleEditorAction('confirm', selectedByAction)
}

async handleCancel () {
await this._handleEditorAction('cancel')
}

async _handleEditorAction (action) {
if (action === 'confirm') {
async _handleEditorAction (action, selectedByAction) {
if (action === 'confirm' && !selectedByAction) {
await this._properties.applyProperties(false)
// await MessageBus.i.request('properties/apply/short', null, null, true)
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/adonisjs/public/dccs/edit/inplace-plain-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class EditDCCPlain {
}
}

async handleConfirm () {
async handleConfirm (selectedByAction) {
this._editElement.contentEditable = false
// <TODO> this will becone an action
this._objProperties[this._objField] =
this._editElement.innerHTML.trim()
.replace(/\u200B/gm, '') // removing non printable special characters
.replace(/(?:<br>)+$/i, '')

await this._properties.applyProperties(false)
if(!selectedByAction){
await this._properties.applyProperties(false)
}
}

// <FUTURE>?
Expand Down
8 changes: 5 additions & 3 deletions src/adonisjs/public/dccs/edit/inplace-text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ class EditDCCText extends EditDCC {
// MessageBus.i.publish('control/knot/update', null, true)
}

async handleConfirm() {
this._updateTranslated()
await this._closeEditor()
async handleConfirm(selectedByAction) {
if(!selectedByAction){
this._updateTranslated()
await this._closeEditor()
}
}

async handleCancel() {
Expand Down
41 changes: 41 additions & 0 deletions src/adonisjs/public/dccs/edit/local-storage-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class LocalStorageStack{
//Class that simulates stack operations for using the local storage key-value database.
//The length of the stack is stored in a item with it's name, the items are stored in a item named stackName + length
constructor(stackName){
//Get item with stack name to get the stored stack if it exists, otherwise create a stack with this name and store 0 as length.
this._stackName = stackName
this.length = localStorage.getItem(stackName)
if(this.length == null){
this.length = 0
localStorage.setItem(stackName, 0)
}
}

push(item){
//push item, increase length and store it
localStorage.setItem(this._stackName + this.length.toString(), item)
this.length++
localStorage.setItem(this._stackName, this.length)
}

pop(){
//Get top item, descrease length and store it
let item = null
if(this.length > 0){
this.length--
localStorage.setItem(this._stackName, this.length)
item = localStorage.getItem(this._stackName + this.length.toString())
localStorage.removeItem(this._stackName + this.length.toString())
}
return item
}

clear(){
//Remove all items from the stack and it's length
while(this.length > 0){
this.length--
localStorage.removeItem(this._stackName + this.length.toString())
}
localStorage.removeItem(this._stackName)
}
}
Loading