Newer
Older
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1><%= title %></h1>
<div id="files"></div>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<div id="app" >
{{ changed }}
<h1><a v-bind:href="'?path=' + files.up + '&dataset_path=' + dataset_path">.. </a></h1>
<template v-if="context">
PTSEFTON
committed
<template v-for="(item, id) in context">
<h2 v-bind:id="id">
<form v-on:submit.prevent="removeItem(id)">
<button type="submit">-</button> {{ id }}
<img width="60%" v-bind:src='item._img'>
<table width="100%" >
<tr v-for="(values, name) in item.properties">
<form v-on:submit.prevent="removeProp(item.properties, name)" style='display:inline;'>
<button type="submit">-</button>
</form>
{{ name }}
</td>
<td>
<form v-on:submit.prevent="addProp(item.properties, name)" style='display:inline;'>
<button type="submit">+</button>
</form>
</td>
<td>
<div v-for="(val, i_index) in values">
<!-- TODO - make sure it's deletable -->
<form v-on:submit.prevent="unlinkProp(val)" style='display:inline;'>
<button type="submit" title="Delete this property">-</button>
</form>
<template v-if="schema.properties[name] && schema.properties[name].input === 'text'">
<input v-model="val.value" type="text" size="45" v-on:keyup="trigger_change_on_enter"/>
</template>
<template v-else-if="val && val.id && context[val.id] && context[val.id].properties.name">
<a v-bind:href="'#' + val.id">{{ context[val.id].properties.name[0].value }}</b></a>
<form v-on:submit.prevent="unlinkProp(val)" style='display:inline;'>
<button type="submit">unlink</button>
</form>
</template>
<b v-else>
{{ val.value }}
</b>
<template v-if="schema.properties[name] && schema.properties[name].input === 'link' " >
<form v-on:submit.prevent="linkProp(val)" style='display:inline;' v-if="!val.id">
<button type="submit"> -> </button>
<select v-model="val.selection" >
<template v-for="(link_item, link_id) in context">
<template v-for="other_name in link_item.properties.name">
<option v-if="(!val.id || link_id != val.id) && schema.properties[name] && link_item.properties.type && schema.properties[name].type.includes(link_item.properties.type[0].value)" v-bind:value="link_id">{{ other_name.value }}</select>
</select>
</form>
<form v-on:submit.prevent="linkToNew(val)" style='display:inline;' v-if="!val.id && schema.properties[name].type.filter(type => {return (schema.types[type] && schema.types[type].create)}).length > 0">
... or ...
<button type="submit" text="Link to a new contextual item"> -> New -> </button>
<select v-model="val.new_type" >
<template v-for="type in schema.properties[name].type.filter(type => {return (schema.types[type] && schema.types[type].create)})">
<option> {{ type }} </option>
</template>
</select>
</select>
</form>
</template>
PTSEFTON
committed
</td>
</tr>
</table>
<form v-on:submit.prevent="addContextProp(item)">
<select v-model="prop_name" >
<template v-for="(prop, prop_name) in schema.properties">
<option v-if="!item.properties[prop_name]">{{prop_name}}</option>
<button type="submit">+</button>
<form v-on:submit.prevent="addContext(context)">
<select v-model="type" >
<option v-for="type_name in Object.getOwnPropertyNames(schema.types).filter(type => {return schema.types[type].create})" v-bind:value="type_name"> {{ type_name }} </option>
</select>
<button type="submit">Add contextual item</button>
</form>
<a v-bind:href="'/?path=' + path + '&dataset_path=' + dataset_path">
<template v-if="files.existing_describo">
</template>
<template v-else>
Package a dataset here
</template>
</a> </h1>
<template v-if="!(context[file.id])">
<img width="50%" v-bind:src='file._img'>
<form v-if="context" v-on:submit.prevent="addFile(file)">
<button type="submit">Add file to package</button>
</form>
</template>
<div id="filelist" border="1">
<ul v-for="dir in files.dirs">
<li><a v-bind:href="'?path=' + dir.absolute + '&dataset_path=' + dataset_path">{{ dir.name }}</a></li>
var context = {};
var schema = {};
document.addEventListener("DOMContentLoaded", function(event) {
const urlParams = new URLSearchParams(window.location.search);
const dataset_path = urlParams.get('dataset_path');
files = response.data;
var params = dataset_path ? '?dataset_path=' + dataset_path : ""
axios.get("/context_entities" + params).then(function(response){
axios.get("/schema").then(function(response){
schema = response.data;
schema: schema,
prop: {"name":"nom", "value": "val"},
type: "Person",
prop_name: "",
link_to_id: {},
link_id: "",
changed: 0,
latest_id: 0,
path: path,
dataset_path: dataset_path
"save_context": function save_context() {
var params = '?dataset_path=' + this.dataset_path;
axios.post('/context_entities' + params, this.context).then(
function () {
}
)
},
"addContextProp": function addContextProp(item){
// Warning! Repetition!
if (item.properties[prop_name]) {
item.properties[prop_name].push({"value": "", "id": ""});
item.properties[prop_name] = [{"value": "", "id": ""}];
}
this.changed += 1;
this.save_context();
},
"addProp": function addProp(item, prop_name){
if (item.properties[prop_name]) {
item.properties[prop_name].push({"value": "", "id": ""});
item.properties[prop_name] = [{"value": "", "id": ""}];
this.changed += 1;
this.save_context();
},
"removeProp": function removeProp(item, prop_name){
delete item[prop_name];
this.changed += 1;
this.save_context();
PTSEFTON
committed
trigger_change_on_enter: function(e) {
if (e.keyCode === 13) {
this.changed += 1;
this.save_context();
}
PTSEFTON
committed
},
"linkProp": function linkProp(val) {
val.value = context[val.selection].properties.name[0].value;
val.id = val.selection;
PTSEFTON
committed
this.changed += 1;
this.save_context();
},
"unlinkProp": function unlinkProp(val) {
val.value = "";
val.id = "";
this.changed += 1;
this.save_context();
},
"addFile": function addFile(file) {
if (!context[file.id]) {
var new_item = JSON.parse(JSON.stringify(schema.types.File.template));
new_item.properties.name[0].value = file.id;
new_item._img = file._img;
context[file.id] = new_item;
this.changed += 1;
this.save_context();
}
else {
alert("Already got that file"); //Should never fire but you never know
}
},
"removeItem": function remove_item(id) {
delete context[id];
this.changed += 1;
this.save_context();
PTSEFTON
committed
"linkToNew" : function linkToNew(val) {
alert(val.new_type);
this.type = val.new_type;
val.id = this.addContext(context);
this.save_context();
},
while (context[this.latest_id.toString()]) {
this.latest_id += 1;
var id = this.latest_id.toString();
context[id] = JSON.parse(JSON.stringify(schema.types[this.type].template));
context[id].properties.name=[{"value": this.type + "(" + id + ")"}]
this.changed += 1;
this.save_context();
return(id);
});
//document.getElementById("files").innerHTML = response['data'].model;
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
})})});