Skip to content

Commit

Permalink
import previous annotation and cmapCloudHome button
Browse files Browse the repository at this point in the history
  • Loading branch information
xabigar committed Nov 21, 2022
1 parent 0a6b0ae commit 32cfc11
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Variants/ConceptAndGo.vdm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<cm:constant cm:id="i0nOl3e7KP1TTb9rK" cm:type="ps:string">xabiergarmendia</cm:constant>
</cm:property>
<cm:property cm:id="iAs39e5sQ_NxhlFQv" cm:type="ps:datetime" cm:fixed="true" cm:readonly="true" cm:name="ps:Changed">
<cm:constant cm:id="iN1wnmEQ6UOvnDBYC" cm:type="ps:datetime">2022-10-05T17:22:50.859Z</cm:constant>
<cm:constant cm:id="iN1wnmEQ6UOvnDBYC" cm:type="ps:datetime">2022-10-19T07:56:41.993Z</cm:constant>
</cm:property>
<cm:property cm:id="iWJuxDiwLkyeNzFxk" cm:type="ps:string" cm:fixed="true" cm:name="iivhJRwmojkiJvYc5/ikd06TuWH0GM-TRbB">
<cm:constant cm:id="ioGS5hLGB_iFK8d0Y" cm:type="ps:string">cag</cm:constant>
Expand All @@ -90,7 +90,7 @@
<cm:constant cm:id="iAHOhwmGgkgHYcXfQ" cm:type="ps:string">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh62oqu5gL13CQVRafRtqaTWkS6UQru7zvTinTn2UxJvFUjsOttkumdEhKh4g4fOvBdYtT07LNsxgVpehKNRiZqdlwSBVIrNTO2vdDKIIHGd4WGYZ/DJLJ7IMgoIvVgvDozH+WwqMEhaeldI+flDAPPswBClT8Sve3npYpM1pZAd9MPyi8HPUXOyJd83gJY3n156rS+DKIEvlR3Ree1Hs8Jns7oNG0AN4+XNZQ3U4vE3W8+YWBfgIn0GOqKnAtza2WPQ2Pml3wupILypaVP7fIt4yQ++YI9ucvOqYzhaD1l1aFi2OMCOZSXNaixQ4PrRooLqGsWoKuiechYE92dijOQIDAQAB</cm:constant>
</cm:property>
<cm:property cm:id="i8UUHEHFFm67mic1-" cm:type="ps:string" cm:fixed="true" cm:name="iivhJRwmojkiJvYc5/iYuM7N7dRcMGZxNk-">
<cm:constant cm:id="iA6nS1smmdq3cT4Bi" cm:type="ps:string">0.2.0</cm:constant>
<cm:constant cm:id="iA6nS1smmdq3cT4Bi" cm:type="ps:string">0.2.1</cm:constant>
</cm:property>
<cm:property cm:id="i7Pb-CBlvD9QufZZ9" cm:type="ps:string" cm:fixed="true" cm:name="iivhJRwmojkiJvYc5/iJML-QuP9BZDq9JNf">
<cm:constant cm:id="ivjAEkGnwv6I2uTyx" cm:type="ps:string">/~https://github.com/onekin/WacLine/wiki/User-manual-for-Concept&amp;Go</cm:constant>
Expand Down
200 changes: 196 additions & 4 deletions WebAnnotator.ccfm

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions input/app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@
"CurrentSelectionNotAnnotable": {
"message": "The selected content cannot be highlighted, is not part of the document"
},
"annotationServerLoginRequired": {
"message": "You need to login in the corresponding annotation server to start annotating. Check instructions to login in the sidebar and reload the page if it is not done automatically."
},
"ErrorContactDeveloper": {
"message": "If the error continues, please <a href='/~https://github.com/onekin/WebAnnotatorSPL/issues/new?title=Bug+$errorMessage$&body=%23+How+to+reproduce%0AWrite+here+any+information+related+to+the+error+found%0A%23+Trace%0A%60$errorStacktrace$%60&labels=bug' target='_blank'>open an issue</a>.",
"placeholders": {
Expand Down
Binary file added input/app/images/cmapCloudHome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions input/app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
// PVSCL:IFCOND(MoodleProvider,LINE)
"exclude_matches": ["*://*/*grade/grading/*", "*://*/*mod/assign/view.php*", "*://*/*course/modedit.php?add=assign*"PVSCL:IFCOND(Manual and Hypothesis), "https://hypothes.is/login"PVSCL:ENDCOND],
//PVSCL:ENDCOND
// PVSCL:IFCOND(CXLExportCmapCloud,LINE)
"exclude_matches": ["https://cmapcloud.ihmc.us/cmaps/myCmaps.html"],
//PVSCL:ENDCOND
"js": ["scripts/contentScript.js"],
"css": ["styles/contentScript.css"],
"run_at": "document_start",
Expand Down Expand Up @@ -78,6 +81,11 @@
"matches": ["*://*/*mod/assign/view.php*"],
"js": ["scripts/moodleEstimation.js"],
"run_at": "document_end"
}PVSCL:ENDCONDPVSCL:IFCOND(CXLExportCmapCloud),
{
"matches": ["https://cmapcloud.ihmc.us/cmaps/myCmaps.html"],
"js": ["scripts/cmapCloudPage.js"],
"run_at": "document_end"
}PVSCL:ENDCOND
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
Expand Down
20 changes: 20 additions & 0 deletions input/app/scripts/cmapCloudPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// import AnnotationBasedInitializer from './contentScript/AnnotationBasedInitializer'
// import ContentScriptManager from './contentScript/ContentScriptManager'
///import _ from 'lodash'



let kudeatzaileakHasieratu = function(){
let checkDOM = setInterval(function () {
let lista = document.getElementById("actions")
let luList = document.getElementById("actions").getElementsByTagName('ul')
let clone = luList[0].firstChild.cloneNode(true)
if (clone.nodeName != '#comment') {
clone.firstChild.innerHTML='Import from Concept&Go'
lista.children[0].appendChild(clone)
clearInterval(checkDOM);
}
}, 1000);
}

window.onload = kudeatzaileakHasieratu
21 changes: 21 additions & 0 deletions input/app/scripts/codebook/operations/read/ReadCodebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,18 +628,21 @@ class ReadCodebook {
items.removeTheme = { name: 'Remove ' + Config.tags.grouped.group }
// PVSCL:IFCOND(Linking,LINE)
items.manageRelationships = { name: 'Manage links' }
items.showAnnotations = { name: 'Show annotations' }
// PVSCL:ENDCOND
} else {
items.updateTheme = { name: 'Modify topic' }
// PVSCL:IFCOND(Linking,LINE)
items.manageRelationships = { name: 'Manage links' }
items.showAnnotations = { name: 'Show annotations' }
// PVSCL:ENDCOND
}
// PVSCL:ELSECOND
items.updateTheme = { name: 'Modify ' + Config.tags.grouped.group }
items.removeTheme = { name: 'Remove ' + Config.tags.grouped.group }
// PVSCL:IFCOND(Linking,LINE)
items.manageRelationships = { name: 'Manage links' }
items.showAnnotations = { name: 'Show annotations' }
// PVSCL:ENDCOND
// PVSCL:ENDCOND
// PVSCL:ENDCOND
Expand Down Expand Up @@ -675,6 +678,24 @@ class ReadCodebook {
window.abwa.mapContentManager.manageRelationships(theme)
}
}
if (key === 'showAnnotations') {
let theme = this.codebook.getCodeOrThemeFromId(themeId)
if (LanguageUtils.isInstanceOf(theme, Theme)) {
window.abwa.annotationServerManager.client.getUserProfile((err, userProfile) => {
if (err) {
console.error('Error while retrieving user profile in hypothesis')
} else {
console.log(userProfile)
let groupId = window.abwa.groupSelector.currentGroup.id
let groupName = window.abwa.groupSelector.currentGroup.name.toLowerCase().replace(/ /g,"-");
let query = '?q=tag:' + Config.namespace + ':' + Config.tags.grouped.group + ':' + theme.name.replace(/ /g,"+");
let url = 'https://hypothes.is/groups/'+groupId+'/'+groupName+query
console.log(url)
window.open(url)
}
})
}
}
// PVSCL:ENDCOND
// PVSCL:ENDCOND
// PVSCL:IFCOND(SidebarNavigation, LINE)
Expand Down
45 changes: 44 additions & 1 deletion input/app/scripts/contentScript/Toolset.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import AnnotationList from '../annotationManagement/read/AnnotationList'
// PVSCL:IFCOND(ImportAnnotations, LINE)
import AnnotationImporter from '../importExport/AnnotationImporter'
// PVSCL:ENDCOND
// PVSCL:IFCOND(Export, LINE)
// PVSCL:IFCOND(JSON, LINE)
import AnnotationExporter from '../importExport/AnnotationExporter'
// PVSCL:ENDCOND
import PreviousVersionAnnotationImporter from '../importExport/PreviousVersionAnnotationImporter'
// PVSCL:IFCOND(CXLExport, LINE)
import { CXLExporter } from '../importExport/cmap/CXLExporter'
// PVSCL:ENDCOND
Expand Down Expand Up @@ -171,6 +172,17 @@ class Toolset {
this.CXLArchiveFileButtonHandler()
// PVSCL:ENDCOND
// PVSCL:IFCOND(CXLExportCmapCloud, LINE)
const cxlCloudHomeImageUrl = chrome.extension.getURL('/images/cmapCloudHome.png')
this.cxlCloudHomeImage = $(toolsetButtonTemplate.content.firstElementChild).clone().get(0)
this.cxlCloudHomeImage.src = cxlCloudHomeImageUrl
this.cxlCloudHomeImage.id = 'cxlCloudHomeButton'
this.cxlCloudHomeImage.title = 'Open CmapCloud folder' // TODO i18n
this.toolsetBody.appendChild(this.cxlCloudHomeImage)
// Add menu when clicking on the button
this.cxlCloudHomeImage.addEventListener('click', () => {
this.CXLCloudHomeButtonHandler()
})

const cxlCloudImageUrl = chrome.extension.getURL('/images/cmapCloud.png')
this.cxlCloudImage = $(toolsetButtonTemplate.content.firstElementChild).clone().get(0)
this.cxlCloudImage.src = cxlCloudImageUrl
Expand All @@ -190,6 +202,21 @@ class Toolset {
// Add menu when clicking on the button
this.seroButtonHandler()
// PVSCL:ENDCOND
const importPreviousVersionImageUrl = chrome.extension.getURL('/images/importExport.png')
this.importPreviousVersionImage = $(toolsetButtonTemplate.content.firstElementChild).clone().get(0)
this.importPreviousVersionImage.src = importPreviousVersionImageUrl
this.importPreviousVersionImage.id = 'importPreviousVersion'
this.importPreviousVersionImage.title = 'Import previous version' // TODO i18n
this.toolsetBody.appendChild(this.importPreviousVersionImage)
this.importPreviousVersionImage.addEventListener('click', () => {
let annotatedResources = window.abwa.annotationManagement.annotationReader.allGroupAnnotations.map(annotation => annotation.target[0].source.url)
annotatedResources = _.uniq(annotatedResources).filter(anno => anno != undefined)
if (annotatedResources) {
PreviousVersionAnnotationImporter.importPreviousVersionAnnotations()
} else {
Alerts.infoAlert({ text: 'You have not annotated documents.', title: 'Problem'})
}
})
// Check if exist any element in the tools and show it
if (!_.isEmpty(this.toolsetBody.innerHTML)) {
this.show()
Expand Down Expand Up @@ -361,6 +388,22 @@ class Toolset {
// PVSCL:ENDCOND
// PVSCL:IFCOND(CXLExportCmapCloud, LINE)

CXLCloudHomeButtonHandler () {
chrome.runtime.sendMessage({ scope: 'cmapCloud', cmd: 'getUserData' }, (response) => {
if (response.data) {
let data = response.data
if (data.userData.user && data.userData.password && data.userData.uid) {
window.open('https://cmapcloud.ihmc.us/cmaps/myCmaps.html')
}
} else {
let callback = () => {
window.open(chrome.extension.getURL('pages/options.html#cmapCloudConfiguration'))
}
Alerts.infoAlert({ text: 'Please, provide us your Cmap Cloud login credentials in the configuration page of the Web extension.', title: 'We need your Cmap Cloud credentials', callback: callback() })
}
})
}

CXLCloudButtonHandler () {
// Create context menu for import export
$.contextMenu({
Expand Down
116 changes: 116 additions & 0 deletions input/app/scripts/importExport/PreviousVersionAnnotationImporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import Alerts from '../utils/Alerts'
import _ from 'lodash'
import Annotation from "../annotationManagement/Annotation";

class PreviousVersionAnnotationImporter {
static askUserToSelectAnnotatedResource (callback) {
// Close sidebar if opened
window.abwa.sidebar.closeSidebar()
let title = 'Select the previous version of this source'
// Get body for classifying
let showForm = () => {
// Create form
let html = PreviousVersionAnnotationImporter.generateFormHTML()
let form = PreviousVersionAnnotationImporter.generateForm()
Alerts.multipleInputAlert({
title: title || '',
html: html,
onBeforeOpen: form.onBeforeOpen,
confirmButtonText: 'Import',
callback: form.callback,
customClass: 'large-swal',
preConfirm: form.preConfirm,
preDeny: form.preDeny
})
}
showForm()
}

static importPreviousVersionAnnotations () {
PreviousVersionAnnotationImporter.askUserToSelectAnnotatedResource((err, jsonObject) => {
if (err) {
Alerts.errorAlert({text: 'Unable to parse json file. Error:<br/>' + err.message})
} else {
}
})
}

static generateForm () {

// Preconfirm
let preConfirmData = {}
let preConfirm = () => {
preConfirmData.value = document.querySelector('#categorizeDropdownPreviousResources').value
}
// Callback
let callback = () => {
console.log(preConfirmData.value)
let selectedResourceAnnotations = _.filter(window.abwa.annotationManagement.annotationReader.allGroupAnnotations, (annotation) => {
return annotation.target[0].source.url === preConfirmData.value
})
if (selectedResourceAnnotations) {
let annotationsForNewVersion = []
let source = window.abwa.targetManager.getDocumentURIs()
// Get document title
source.title = window.abwa.targetManager.documentTitle || ''
// Get UUID for current target
source.id = window.abwa.targetManager.getDocumentId()
selectedResourceAnnotations.forEach( annotation => {
let target = [{}]
target[0].source = source
target[0].selector = annotation.target[0].selector
let annotationToCreate = new Annotation({
target: target,
tags: annotation.tags,
body: annotation.body
})
annotationToCreate.serialize()
// annotationsForNewVersion.push(annotationToCreate)
window.abwa.annotationServerManager.client.createNewAnnotation(annotationToCreate.serialize(), (err, annotation) => {
if (err) {
Alerts.errorAlert({text: 'Unable to create new group.'})
} else {
// Parse annotations and dispatch created codebook
console.log(annotation)
}
})
})
console.log(annotationsForNewVersion)
Alerts.simpleSuccessAlert({ text: 'Saved' })
}
}
return { preConfirm: preConfirm, callback: callback }
}

static generateFormHTML () {
let html = ''

// Create input
let inputFrom = document.createElement('select')
inputFrom.id = 'categorizeDropdownPreviousResources'
inputFrom.className = 'annotatedResourceInput'
inputFrom.placeholder = 'Select an annotated resource'
inputFrom.setAttribute('list', 'resources')

let annotatedResources = window.abwa.annotationManagement.annotationReader.allGroupAnnotations.map(annotation => annotation.target[0].source.url)
annotatedResources = _.uniq(annotatedResources).filter(anno => anno != undefined)
console.log(annotatedResources)

// create options

if (annotatedResources) {
annotatedResources.forEach(anno => {
let option = document.createElement('option')
option.value = anno
option.text = anno
inputFrom.add(option)
})
}
// RENDER
html += inputFrom.outerHTML

return html
}
}

export default PreviousVersionAnnotationImporter
3 changes: 2 additions & 1 deletion input/app/scripts/utils/Alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (document && document.head) {
}

class Alerts {
static confirmAlert ({ alertType = Alerts.alertType.info, title = '', text = '', confirmButtonText = 'OK', cancelButtonText = 'Cancel', reverseButtons, allowOutsideClick = true, allowEscapeKey = true, callback, cancelCallback }) {
static confirmAlert ({ alertType = Alerts.alertType.info, title = '', text = '', confirmButtonText = 'OK', cancelButtonText = 'Cancel', onBeforeOpen, reverseButtons, allowOutsideClick = true, allowEscapeKey = true, callback, cancelCallback }) {
Alerts.tryToLoadSwal()
if (_.isNull(swal)) {
if (_.isFunction(callback)) {
Expand All @@ -20,6 +20,7 @@ class Alerts {
confirmButtonText,
cancelButtonText,
reverseButtons,
willOpen: onBeforeOpen,
allowOutsideClick,
allowEscapeKey,
showCancelButton: true
Expand Down

0 comments on commit 32cfc11

Please sign in to comment.