Skip to content

Commit

Permalink
check issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
mvtdev1050 committed Feb 3, 2021
1 parent 30f2b5f commit 939a23a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
},
"config": {
"DrawioEditorBaseURL": {
"value": "http://localhost/drawio.git/src/main/webapp/",
"value": "http://localhost/Projects/mediawiki/mediawiki-1.35.0/extensions/drawio/src/main/webapp/",
"description": "URL to the DrawIO webapp"
},
"DrawioEditorImageType": {
Expand Down
16 changes: 12 additions & 4 deletions resources/ext.drawioeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function DrawioEditor(id, filename, type, interactive, updateHeight, updateWidth
} else if (this.imgType == 'png') {
this.imgMimeType = 'image/png';
} else {
throw new Error('unkown file type');
throw new Error('unknown file type');
}

this.imageBox = $("#drawio-img-box-" + id);
Expand Down Expand Up @@ -188,26 +188,33 @@ DrawioEditor.prototype.loadImageFromDataURL = function(type, dataurl) {
}

DrawioEditor.prototype.loadImage = function() {
if (!this.imageURL.length) {
// if (!this.imageURL.length) {
if (this.imageURL == undefined) {
// just load without data if there's no current image
this.sendMsgToIframe(
{
action: 'load',
autosave: 1 // FIXME: LMP: Causes update event notification on every change
});
return;
this.hideSpinner();
return;
}
// fetch image from wiki. it must contain both image data and
// draw.io xml data. see DrawioEditor.saveCallback()
this.downloadFromWiki();
}

DrawioEditor.prototype.uploadToWiki = function(blob) {
var enterd_filename = document.getElementsByClassName('oo-ui-inputWidget-input')[0].value;
if(this.filename == 'ChartName5' && (enterd_filename != '' && enterd_filename != this.filename)) {
this.filename = enterd_filename;
}
var that = this;
var api = new mw.Api();
api.upload(blob, { filename: this.filename+'.drawio.png', ignorewarnings: 1, format: 'json' } )
.done( function(data) {
if (!data.upload) {
console.log("done");
if (!data.upload) {
if (data.error) {
that.showDialog('Save failed',
'The wiki returned the follwing error when uploading:<br>' +
Expand All @@ -225,6 +232,7 @@ DrawioEditor.prototype.uploadToWiki = function(blob) {
}
})
.fail( function(retStatus, data) {
console.log("error");
if( retStatus == "exists" ){
that.updateImage(data.upload.imageinfo);
that.hideSpinner();
Expand Down
33 changes: 8 additions & 25 deletions resources/modules/ve/node/ve.ce.MWDrawIOBlockExtensionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ ve.ce.MWDrawIOBlockExtensionNode.prototype.update = async function () {

if ( requiresInteractive ) {
if ( !this.map && this.getRoot() ) {
this.setupMap();
var that_this = this;
// this.setupMap();
setTimeout(function(){
that_this.setupMap();
}, 500);
// setTimeout(this.setupMap(), 20000);
/* LMP-FIXME
mw.loader.using( [
'ext.kartographer.box',
Expand All @@ -143,32 +148,10 @@ ve.ce.MWDrawIOBlockExtensionNode.prototype.update = async function () {
} else if ( this.map ) {
// update image src in image
var mwData = this.model.getAttribute( 'mw' );
// var filename = mwData.attrs.filename;
// var type = mwData.attrs.type;

// var params = {
// action: 'query',
// format: 'json',
// prop: 'imageinfo',
// titles: 'File:'+filename+'.drawio.'+type,
// iiprop: [ 'timestamp', 'user', 'url' ]
// },
// api = new mw.Api();

var src = "";
var src_time = "";

// await api.get( params ).done( function ( data ) {
// var pages = data.query.pages,
// p;
// for ( p in pages ) {
// src = pages[ p ].imageinfo[0].url;
// // src_time = pages[ p ].imageinfo[0].url+ '?ts=' + pages[ p ].imageinfo[0].timestamp;
// var timestamp = new Date().getTime();
// src_time = pages[ p ].imageinfo[0].url+ '?ts=' + timestamp;
// }
// } );

await this.callImageApi(mwData).then( function ( data ) {
src = data;
var timestamp = new Date().getTime();
Expand Down Expand Up @@ -244,7 +227,7 @@ ve.ce.MWDrawIOBlockExtensionNode.prototype.setupMap = async function () {
var timestamp = new Date().getTime();
src_time = src+ '?ts=' + timestamp;
});

console.log("src_time",src_time);
var title = "drawio: "+filename;

this.$wavedromdiv=$( '<img id="drawio-img-775430669" src="'+src_time+'" title="'+title+'" alt="'+title+'" style="height: auto; width: 100%; max-width: 371px;"></img>' );
Expand Down Expand Up @@ -288,7 +271,7 @@ ve.ce.MWDrawIOBlockExtensionNode.prototype.callImageApi = async function (mwData
var type = mwData.attrs.type;

var src = "";

var params = {
action: 'query',
format: 'json',
Expand Down
29 changes: 24 additions & 5 deletions resources/modules/ve/node/ve.ui.MWDrawIOBlockExtensionDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,26 @@ ve.ui.MWDrawIOBlockExtensionDialog.prototype.updateMwData = function ( mwData )
if(this.editor) {
this.editor.saveCallback();
}

// check here if filename value is present in mwdata i.e. if insert or edit
var filename = 'ChartName5';
if(mwData.attrs.filename == undefined) {
// check if input has value
var enterd_filename = document.getElementsByClassName('oo-ui-inputWidget-input')[0].value;
if(enterd_filename !== '' && enterd_filename !== 'undefined') {
filename = enterd_filename;
}
} else {
filename = mwData.attrs.filename;
}
mwData.attrs.filename = filename;

if(mwData.attrs.type == undefined) {
mwData.attrs.type = 'png';
}

// check here if filename value is present in mwdata i.e. if insert or edit

var center, scaled, latitude, longitude, zoom,
dimensions = // this.scalable.getBoundedDimensions(
this.dimensions.getDimensions()
Expand All @@ -455,8 +475,8 @@ ve.ui.MWDrawIOBlockExtensionDialog.prototype.updateMwData = function ( mwData )

// if ( !( this.selectedNode instanceof ve.dm.MWDrawIOTransclusionNode2 ) )
{
// mwData.attrs.width = dimensions.width.toString();
// mwData.attrs.height = dimensions.height.toString();
// mwData.attrs.width = dimensions.width.toString();
// mwData.attrs.height = dimensions.height.toString();

if( isSelected ) {
// LMP: Case of just freshly un-selecting the wrap button, this is null - default to left
Expand All @@ -465,7 +485,6 @@ ve.ui.MWDrawIOBlockExtensionDialog.prototype.updateMwData = function ( mwData )
if( selected === null ) selected=this.alignWidget.selectItemByData( 'left' );

mwData.attrs.align = selected.getData();

// XXX
debugger;
}
Expand Down Expand Up @@ -544,8 +563,8 @@ ve.ui.MWDrawIOBlockExtensionDialog.prototype.getSetupProcess = function ( data )
mwAttrs = this.selectedNode && this.selectedNode.getAttribute( 'mw' ).attrs || {};


// FIXME> DrawIO handling should go here
// this.input.clearUndoStack();
// FIXME> DrawIO handling should go here
// this.input.clearUndoStack();

this.actions.setMode( this.selectedNode ? 'edit' : 'insert' );

Expand Down

0 comments on commit 939a23a

Please sign in to comment.