@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 3.3 kB
JavaScript
GitHubFile=function(t,i,e){DrawioFile.call(this,t,i),this.meta=e,this.peer=this.ui.gitHub},mxUtils.extend(GitHubFile,DrawioFile),GitHubFile.prototype.share=function(){this.ui.editor.graph.openLink("https://github.com/"+encodeURIComponent(this.meta.org)+"/"+encodeURIComponent(this.meta.repo)+"/settings/access")},GitHubFile.prototype.getId=function(){return encodeURIComponent(this.meta.org)+"/"+(null!=this.meta.repo?encodeURIComponent(this.meta.repo)+"/"+(null!=this.meta.ref?this.meta.ref+(null!=this.meta.path?"/"+this.meta.path:""):""):"")},GitHubFile.prototype.getHash=function(){return encodeURIComponent("H"+this.getId())},GitHubFile.prototype.getPublicUrl=function(t){null!=this.meta.download_url?mxUtils.get(this.meta.download_url,mxUtils.bind(this,(function(i){t(i.getStatus()>=200&&i.getStatus()<=299?this.meta.download_url:null)})),mxUtils.bind(this,(function(){t(null)}))):t(null)},GitHubFile.prototype.isConflict=function(t){return null!=t&&409==t.status},GitHubFile.prototype.getMode=function(){return App.MODE_GITHUB},GitHubFile.prototype.isAutosave=function(){return!1},GitHubFile.prototype.getTitle=function(){return this.meta.name},GitHubFile.prototype.isRenamable=function(){return!1},GitHubFile.prototype.getLatestVersion=function(t,i){this.peer.getFile(this.getId(),t,i)},GitHubFile.prototype.isCompressedStorage=function(){return!1},GitHubFile.prototype.getDescriptor=function(){return this.meta},GitHubFile.prototype.setDescriptor=function(t){this.meta=t},GitHubFile.prototype.getDescriptorEtag=function(t){return t.sha},GitHubFile.prototype.setDescriptorEtag=function(t,i){t.sha=i},GitHubFile.prototype.save=function(t,i,e,s,n,o){this.doSave(this.getTitle(),i,e,s,n,o)},GitHubFile.prototype.saveAs=function(t,i,e){this.doSave(t,i,e)},GitHubFile.prototype.doSave=function(t,i,e,s,n,o){var l=this.meta.name;this.meta.name=t,DrawioFile.prototype.save.apply(this,[null,mxUtils.bind(this,(function(){this.meta.name=l,this.saveFile(t,!1,i,e,s,n,o)})),e,s,n])},GitHubFile.prototype.saveFile=function(t,i,e,s,n,o,l){if(this.isEditable())if(this.savingFile)null!=s&&s({code:App.ERROR_BUSY});else{var a=mxUtils.bind(this,(function(i){if(this.getTitle()==t)try{this.savingFileTime=new Date,this.setShadowModified(!1),this.savingFile=!0;var n=this.getCurrentEtag(),l=this.data;this.peer.saveFile(this,mxUtils.bind(this,(function(t){this.setModified(this.getShadowModified()),this.savingFile=!1,this.setDescriptorEtag(this.meta,t),this.fileSaved(l,n,mxUtils.bind(this,(function(){this.contentChanged(),null!=e&&e()})),s)})),mxUtils.bind(this,(function(t){this.savingFile=!1,this.isConflict(t)?(this.inConflictState=!0,null!=s&&s({commitMessage:i})):null!=s&&s(t)})),o,i)}catch(t){if(this.savingFile=!1,null==s)throw t;s(t)}else this.savingFileTime=new Date,this.setShadowModified(!1),this.savingFile=!0,this.ui.pickFolder(this.getMode(),mxUtils.bind(this,(function(n){this.peer.insertFile(t,this.getData(),mxUtils.bind(this,(function(t){this.setModified(this.getShadowModified()),this.savingFile=!1,null!=e&&e(),this.ui.fileLoaded(t)})),mxUtils.bind(this,(function(){this.savingFile=!1,null!=s&&s()})),!1,n,i)})))}));null!=l?a(l):this.peer.showCommitDialog(this.meta.name,null==this.getDescriptorEtag(this.meta)||this.meta.isNew,mxUtils.bind(this,(function(t){a(t)})),s)}else null!=e&&e()};