UNPKG

graphdb-workbench

Version:
2 lines 12 kB
export const __webpack_id__=66014;export const __webpack_ids__=[15435,56139,56413,66014,71156,83610,84923];export const __webpack_modules__={15435:(n,e,t)=>{t.r(e),t.d(e,{RenderingMode:()=>o});const o={YASGUI:"mode-yasgui",YASQE:"mode-yasqe",YASR:"mode-yasr"}},56139:()=>{function n(n,e){return{showToastMessageWithDelay:function(t){return new Promise(o=>{n.success(e.instant(t)),setTimeout(o,300)})}}}angular.module("graphdb.framework.utils.notifications",[]).factory("Notifications",n),n.$inject=["toastr","$translate"]},56413:(n,e,t)=>{t.r(e),t.d(e,{DEFAULT_SPARQL_QUERY:()=>o,JdbcConfigurationInfo:()=>i});const o="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n\n# Selects two variables to use as columns\nSELECT ?id ?label {\n ?id rdfs:label ?label\n # The following placeholder must be present in the query\n #!filter\n}";class i{constructor(n=o,e=!0,t=void 0){this.query=n,this.jdbcConfigurationName=t,this.isNewJdbcConfiguration=e,this.isValidQuery=!0,this.isValidQueryType=!0,this.hasUndefinedColumns=!1,this.isColumnsEmpty=!1,this.columns=[]}}},66014:(n,e,t)=>{t.r(e),t(76933),t(83351),t(56139),t(82493),t(81655);var o=t(56413),i=t(71156),r=t(84923),s=t(15435),a=t(83610),c=t(85727),u=t(69937),l=t(57154);function g(n,e,t,o,i,r){n.getSqlConfigurations=function(){!e.getActiveRepository()||e.isActiveRepoOntopType()||e.isActiveRepoFedXType()?n.jdbcConfigurations=[]:t.getJdbcConfigurations().success(function(e){n.jdbcConfigurations=e}).error(function(n){const e=getError(n);o.error(e,r.instant("jdbc.not.get.SQL.msg"))})},n.$watch(function(){return e.getActiveRepository()},function(){n.getSqlConfigurations()}),n.deleteConfiguration=function(e){i.openSimpleModal({title:r.instant("common.warning"),message:r.instant("jdbc.delete.sql.table.warning.msg",{name:e}),warning:!0}).result.then(function(){t.deleteJdbcConfiguration(e).success(function(){n.getSqlConfigurations()}).error(function(n){o.error(getError(n),r.instant("jdbc.not.delete.sql.msg"))})})}}function d(n,e,t,g,d,f,m,b,p,C,y,h,j,w,v,R){e.emptySparqlResponse='{"head": {"vars": []},"results": {"bindings": []}}',e.getSuggestionSqlType="",e.sqlTypes=[],e.activeTab=1,e.jdbcConfigurationInfo=new o.JdbcConfigurationInfo,e.jdbcConfigurationInfo.jdbcConfigurationName=g.search().name||"",e.saveOrUpdateExecuted=!1,e.jdbcConfigurationInfo.isNewJdbcConfiguration=!e.jdbcConfigurationInfo.jdbcConfigurationName,e.language=v.getLanguage(),e.isDirty=!1,e.prefixes=[],e.loadingControllerResources=!1,e.isQueryRunning=!1,e.canEditActiveRepo=!1;let S=!0,q=!0;e.saveJdbcConfiguration=()=>{if(e.saveOrUpdateExecuted=!0,!e.jdbcConfigurationInfo.jdbcConfigurationName)return;if(!e.isDirty)return void F();const n=e.jdbcConfigurationInfo.isNewJdbcConfiguration?_:A;Q(e.jdbcConfigurationInfo).then(D).then(P).then(U).then(n).catch(n=>{if(!(n instanceof r.JdbcConfigurationError)){const e=getError(n);d.error(e,w.instant("jdbc.not.saved.configuration"))}})},e.getPreview=()=>{e.activeTab=1,e.isQueryRunning=!0,Q(e.jdbcConfigurationInfo).then(D).then(P).then(U).then(n=>(J({render:s.RenderingMode.YASQE,initialQuery:n.query}),n)).then(E).then(([n,e])=>{const t=n&&n.results.bindings&&n.results.bindings.length>0;let o=s.RenderingMode.YASGUI;t||(o=s.RenderingMode.YASQE,d.info(w.instant("jdbc.table.definition"),w.instant("jdbc.preview.sql"))),J({render:o,sparqlResponse:n,initialQuery:e.query})}).catch(n=>{n instanceof r.JdbcConfigurationError?n.jdbcConfigurationInfo&&(n.jdbcConfigurationInfo.isColumnsEmpty||n.jdbcConfigurationInfo.hasUndefinedColumns)&&($(),e.activeTab=2):d.error(getError(n,0,100),w.instant("jdbc.not.show.preview"))}).finally(()=>{e.isQueryRunning=!1})},e.setActiveTab=n=>{e.activeTab=n;const t=e.jdbcConfigurationInfo.columns;2!==e.activeTab||t&&0!==t.length||Q(e.jdbcConfigurationInfo).then(D).then(()=>{e.getColumnsSuggestions()})},e.setDirty=()=>{e.isDirty=!0},e.getTypeLabel=n=>{switch(n){case"iri":return"VARCHAR: IRI";case"string":return"VARCHAR: String";default:return n.indexOf(" ")>0?n:n.toUpperCase()}},e.selectColumnType=(n,t)=>{e.setDirty();const o=e.jdbcConfigurationInfo.columns.find(e=>e.column_name===n);o.column_type===e.getSuggestionSqlType&&U(e.jdbcConfigurationInfo).then(e=>C.getColumnsTypeSuggestion(e.query,[n])).then(n=>n.data).then(n=>{(0,a.updateColumn)(o,n),I(o.column_type,t)}).catch(n=>{d.error(getError(n),w.instant("jdbc.not.suggest.column.type"))})},e.deleteColumn=function(n,t){j.openSimpleModal({title:w.instant("common.warning"),message:w.instant("jdbc.warning.delete.column.msg",{columnName:n}),warning:!0}).result.then(function(){e.jdbcConfigurationInfo.columns.splice(t,1),e.setDirty()})},e.getColumnsSuggestions=()=>{e.jdbcConfigurationInfo.columns&&e.jdbcConfigurationInfo.columns.length>0?j.openSimpleModal({title:w.instant("common.warning"),message:w.instant("jdbc.warning.column.type.msg"),warning:!0}).result.then(function(){$()}):$()},e.hasPrecision=n=>"iri"===n||"string"===n||"decimal"===n,e.containsColumnsWithPrecision=n=>n&&n.some(n=>e.hasPrecision(n.column_type)),e.containsColumnsWithScale=n=>n&&n.some(n=>Y(n.column_type)),e.isLiteral=n=>"iri"!==n&&"unknown"!==n,e.containsNonLiteralColumnsOnly=n=>n&&n.every(n=>!e.isLiteral(n.column_type));const E=n=>{if(e.canWriteActiveRepo){const t=JSON.stringify({name:e.jdbcConfigurationInfo.jdbcConfigurationName,query:e.jdbcConfigurationInfo.query,columns:e.jdbcConfigurationInfo.columns||[]});return Promise.all([C.getNewSqlTablePreview(t).then(n=>n.data),Promise.resolve(n)])}return Promise.all([C.getExistingSqlTablePreview(e.jdbcConfigurationInfo.jdbcConfigurationName).then(n=>n.data),Promise.resolve(n)])},I=(n,e)=>{n===e?d.info((0,u.Gz)(w.instant("jdbc.same.suggested.sql.type",{type:n})),w.instant("jdbc.suggest.sql.type"),{allowHtml:!0}):d.success((0,u.Gz)(w.instant("jdbc.suggested.sql.type",{type:n})),w.instant("jdbc.suggest.sql.type"),{allowHtml:!0})},T=(n,t=new o.JdbcConfigurationInfo)=>{e.jdbcConfigurationInfo.columns=t.columns,e.jdbcConfigurationInfo.query=t.query,e.jdbcConfigurationInfo.jdbcConfigurationName=g.search().name||"",e.jdbcConfigurationInfo.isNewJdbcConfiguration=!e.jdbcConfigurationInfo.jdbcConfigurationName,e.prefixes=n,J(),V()},_=n=>{const t={name:n.jdbcConfigurationName,query:n.query,columns:n.columns};return C.createNewJdbcConfiguration(t).then(()=>{e.isDirty=!1,e.jdbcConfigurationInfo.isNewConfiguration=!1,d.success(w.instant("jdbc.saved.configuration")),W()})},A=n=>{const t={name:n.jdbcConfigurationName,query:n.query,columns:n.columns};return C.updateJdbcConfiguration(t).then(()=>{e.isDirty=!1,e.jdbcConfigurationInfo.isNewConfiguration=!1,d.success(w.instant("jdbc.configuration.updated")),W()})},J=(n={})=>{const t={};angular.extend(t,e.yasguiConfig||N(),n),e.yasguiConfig=t},N=()=>({showEditorTabs:!1,showToolbar:!1,showResultTabs:!1,showQueryButton:!1,showResultInfo:!1,downloadAsOn:!1,showYasqeResizer:!1,initialQuery:e.jdbcConfigurationInfo.query,componentId:"jdbc-component",prefixes:e.prefixes,maxPersistentResponseSize:0,render:s.RenderingMode.YASQE,getCellContent:O,sparqlResponse:e.emptySparqlResponse,yasqeActionButtons:c.DISABLE_YASQE_BUTTONS_CONFIGURATION,yasqeMode:e.canEditActiveRepo?i.YasqeMode.WRITE:i.YasqeMode.READ}),Q=n=>L().getQueryType().then(e=>(n.isValidQueryType="SELECT"===e,n.isValidQueryType?n:Promise.reject(new r.JdbcConfigurationError("Query type is not valid.")))),D=n=>L().isQueryValid().then(e=>(n.isValidQuery=e,n.isValidQuery?n:Promise.reject(new r.JdbcConfigurationError("Invalid query.")))),P=n=>n.columns&&0!==n.columns.length?e.jdbcConfigurationInfo.columns&&e.jdbcConfigurationInfo.columns.find(n=>"unknown"===n.column_type)?(n.hasUndefinedColumns=!0,Promise.reject(new r.JdbcConfigurationError("There are columns without defined type.",n))):Promise.resolve(n):(n.isColumnsEmpty=!0,d.error(w.instant("jdbc.warning.one.column.msg")),Promise.reject(new r.JdbcConfigurationError("There are not defined columns.",n))),$=()=>{Q(e.jdbcConfigurationInfo).then(D).then(U).then(x).then(M).then(n=>e.jdbcConfigurationInfo=n).catch(n=>{console.log(n)})},x=n=>C.getColumnNames(n.query).then(e=>[n,e.data]).catch(function(n){d.error(getError(n),w.instant("jdbc.not.suggest.column.names"))}),M=([n,t])=>C.getColumnsTypeSuggestion(n.query,t).then(function(o){return n.columns=(0,a.toJDBCColumns)(t,o.data),n.isColumnsEmpty=n.columns.length,e.setDirty(),n}).catch(function(n){d.error(getError(n),w.instant("jdbc.not.suggest.column.types"))}),L=()=>c.YasguiComponentDirectiveUtil.getOntotextYasguiElement("#query-editor"),U=n=>L().getQuery().then(e=>(n.query=e,n)),Y=n=>"decimal"===n,O=(n,e)=>{let t=n.value;return t=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),"<div class = 'literal-cell'><p class='nonUri' style='border: none; background-color: transparent; padding: 0; margin: 0'>"+t+"</p></div>"},k=(n,e,t,o)=>{j.openSimpleModal({title:n,message:e,warning:!0}).result.then(function(){angular.isFunction(t)&&t()},function(){angular.isFunction(o)&&o()})},V=()=>{e.getSuggestionSqlType=w.instant("view.jdbc.create.get_suggestion_sql_type"),e.sqlTypes=["string","iri","boolean","byte","short","int","long","float","double","decimal","date","time","timestamp",e.getSuggestionSqlType]},W=()=>{setTimeout(function(){F()},1e3)},F=()=>{g.url("/jdbc")},B=n=>{e.isDirty&&(n.returnValue=!0)},G=()=>{window.removeEventListener("beforeunload",B),z.forEach(n=>n())},z=[],H=l.ServiceProvider.get(l.RepositoryContextService).onSelectedRepositoryChanged(n=>{n&&(q?q=!1:L().abortQuery().then(F))},()=>new Promise(function(n){if(e.jdbcConfigurationInfo.isNewJdbcConfiguration)return void n(!0);const t=()=>{e.isDirty=!1,n(!0)};if(e.isDirty){const e=()=>{n(!1)},o=w.instant("common.confirm"),i=w.instant("jdbc.warning.unsaved.changes");k(o,i,t,e)}else t()}));z.push(H),z.push(t.$on("$translateChangeSuccess",()=>{e.language=v.getLanguage(),V()})),z.push(e.$on("$locationChangeStart",(n,t)=>{if(e.isDirty){n.preventDefault();const e=w.instant("common.confirm"),o=w.instant("jdbc.warning.unsaved.changes");k(e,o,()=>{G();const n=g.absUrl().length-g.url().length,e=t.substring(n);g.path(e)})}else G()})),z.push(e.$on("$destroy",G)),window.addEventListener("beforeunload",B),z.push(e.$watch(e.getActiveRepositoryObject,n=>{n&&(e.canEditActiveRepo=e.canWriteActiveRepo(),S?((()=>{e.loadingControllerResources=!0;const n=f.getActiveRepository();e.jdbcConfigurationInfo.jdbcConfigurationName?Promise.all([f.getPrefixes(n),C.getJdbcConfiguration(e.jdbcConfigurationInfo.jdbcConfigurationName)]).then(([n,e])=>{T(n,e.data)}).finally(()=>e.loadingControllerResources=!1):f.getPrefixes(n).then(n=>T(n)).finally(()=>e.loadingControllerResources=!1)})(),S=!1):L().abortQuery().then(F))}))}angular.module("graphdb.framework.jdbc.controllers",["ui.bootstrap","graphdb.framework.core.services.repositories","graphdb.framework.rest.monitoring.service","toastr","graphdb.framework.utils.event-emitter-service"],["graphdb.framework.utils.notifications"]).controller("JdbcListCtrl",g).controller("JdbcCreateCtrl",d),g.$inject=["$scope","$repositories","JdbcRestService","toastr","ModalService","$translate"],d.$inject=["$q","$scope","$rootScope","$location","toastr","$repositories","$window","$timeout","$interval","JdbcRestService","RDF4JRepositoriesRestService","SparqlRestService","ModalService","$translate","$languageService","EventEmitterService"]},71156:(n,e,t)=>{t.r(e),t.d(e,{YasqeMode:()=>o});const o={WRITE:"WRITE",READ:"READ",PROTECTED:"PROTECTED"}},83610:(n,e,t)=>{t.r(e),t.d(e,{JdbcColumn:()=>o,toJDBCColumns:()=>i,updateColumn:()=>r});class o{constructor(){this.column_name="",this.column_type="",this.sparql_type="",this.nullable=!0}}const i=(n=[],e)=>n.map(n=>({column_name:n,column_type:e[n].column_type,nullable:!0,sparql_type:e[n].sparql_type})),r=(n,e)=>{n.column_type=e[n.column_name].column_type,n.sparql_type=e[n.column_name].sparql_type}},84923:(n,e,t)=>{t.r(e),t.d(e,{JdbcConfigurationError:()=>o});class o extends Error{constructor(n,e){super(n),this.jdbcConfigurationInfo=e}}}}; //# sourceMappingURL=66014.336bc4291da2fbc96cd1.bundle.js.map