Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
SemWeb
libview
Commits
c52b4cd1efdd
Commit
1685a178
authored
Sep 06, 2018
by
Laurent Wouters
Browse files
[feature] Browser support for supplementary resources
parent
5da732a18098
Changes
16
Show whitespace changes
Inline
Side-by-side
build.sh
View file @
c52b4cd1
...
...
@@ -3,14 +3,6 @@
SCRIPT
=
"
$(
readlink
-f
"
$0
"
)
"
ROOT
=
"
$(
dirname
"
$SCRIPT
"
)
"
echo
""
echo
"=========================================="
echo
"= Building @logilab/librdf"
echo
"=========================================="
(
cd
"
$ROOT
/librdf"
;
rm
-rf
build
)
(
cd
"
$ROOT
/librdf"
;
npm
install
)
(
cd
"
$ROOT
/librdf"
;
npm run build
)
echo
""
echo
"=========================================="
echo
"= Building @logilab/libview"
...
...
@@ -24,7 +16,6 @@ echo "=========================================="
echo
"= Building @logilab/views-logilab"
echo
"=========================================="
(
cd
"
$ROOT
/views-logilab"
;
rm
-rf
build
)
(
cd
"
$ROOT
/views-logilab"
;
rm
-rf
node_modules/@logilab/librdf
)
(
cd
"
$ROOT
/views-logilab"
;
rm
-rf
node_modules/@logilab/libview
)
(
cd
"
$ROOT
/views-logilab"
;
npm
install
)
(
cd
"
$ROOT
/views-logilab"
;
npm run build
)
...
...
@@ -34,7 +25,6 @@ echo "=========================================="
echo
"= Building @logilab/ld-browser"
echo
"=========================================="
(
cd
"
$ROOT
/extension"
;
rm
-rf
build
)
(
cd
"
$ROOT
/extension"
;
rm
-rf
node_modules/@logilab/librdf
)
(
cd
"
$ROOT
/extension"
;
rm
-rf
node_modules/@logilab/libview
)
(
cd
"
$ROOT
/extension"
;
npm
install
)
(
cd
"
$ROOT
/extension"
;
npm run build
)
extension/package.json
View file @
c52b4cd1
...
...
@@ -20,7 +20,6 @@
"author"
:
"LOGILAB <contact@logilab.fr>"
,
"license"
:
"LGPL-3.0"
,
"dependencies"
:
{
"@logilab/librdf"
:
"file:../librdf"
,
"@logilab/libview"
:
"file:../libview"
,
"bootstrap"
:
"^4.1.1"
,
"jquery"
:
"^1.12.4"
,
...
...
extension/src/ldbrowser/browser.ts
View file @
c52b4cd1
...
...
@@ -328,9 +328,20 @@ class LDBrowserImpl implements LDBrowser {
uris
.
forEach
(
async
(
uri
:
string
)
=>
{
let
childResource
=
await
self
.
resolveResourceData
(
uri
);
let
childStore
=
await
self
.
resolveRdfStore
(
childResource
);
childStore
.
statements
.
forEach
((
statement
:
$rdf
.
Statement
)
=>
parentStore
.
addStatement
(
statement
)
childStore
.
statements
.
forEach
((
statement
:
$rdf
.
Statement
)
=>
{
parentStore
.
add
(
statement
.
subject
.
termType
==
"
NamedNode
"
?
parentStore
.
sym
(
statement
.
subject
.
value
)
:
statement
.
subject
,
statement
.
predicate
.
termType
==
"
NamedNode
"
?
parentStore
.
sym
(
statement
.
predicate
.
value
)
:
statement
.
predicate
,
statement
.
object
.
termType
==
"
NamedNode
"
?
parentStore
.
sym
(
statement
.
object
.
value
)
:
statement
.
object
,
statement
.
graph
);
});
resource
.
supplements
.
push
(
uri
);
onFinishedPart
();
});
...
...
librdf/package.json
deleted
100644 → 0
View file @
5da732a1
{
"name"
:
"@logilab/librdf"
,
"version"
:
"0.1.0"
,
"description"
:
"Library for complementary RDF utilities."
,
"scripts"
:
{
"build"
:
"webpack"
,
"clean"
:
"rm -rf build/*"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"build:production"
:
"NODE_ENV=production webpack"
},
"main"
:
"./build/index.js"
,
"types"
:
"./build/lib/index.d.ts"
,
"repository"
:
{
"type"
:
"hg"
,
"url"
:
"https://bitbucket.org/laurentw/logilab-cubicweb-client"
},
"keywords"
:
[
"DataBrowser"
,
"Typescript"
],
"author"
:
"LOGILAB <contact@logilab.fr>"
,
"license"
:
"LGPL-3.0"
,
"dependencies"
:
{
"rdflib"
:
"^0.17.0"
},
"devDependencies"
:
{
"@types/node"
:
"^10.5.3"
,
"@types/rdflib"
:
"^0.17.0"
,
"source-map-loader"
:
"^0.2.3"
,
"ts-loader"
:
"^4.4.2"
,
"typescript"
:
"^2.9.2"
,
"webpack"
:
"^4.0.1"
,
"webpack-cli"
:
"^2.0.10"
}
}
librdf/tsconfig.json
deleted
100644 → 0
View file @
5da732a1
{
"compilerOptions"
:
{
"outDir"
:
"./lib/"
,
"sourceMap"
:
true
,
"declaration"
:
true
,
"noImplicitAny"
:
true
,
"module"
:
"commonjs"
,
"target"
:
"es6"
,
"lib"
:
[
"es6"
,
"dom"
],
"jsx"
:
"react"
},
"include"
:
[
"./src/**/*"
],
}
\ No newline at end of file
librdf/webpack.config.js
deleted
100644 → 0
View file @
5da732a1
const
path
=
require
(
"
path
"
);
const
isProd
=
process
.
env
.
NODE_ENV
===
"
production
"
;
module
.
exports
=
[
{
entry
:
"
./src/index.ts
"
,
mode
:
isProd
?
"
production
"
:
"
development
"
,
output
:
{
path
:
path
.
resolve
(
__dirname
,
"
build/
"
),
filename
:
"
index.js
"
,
libraryTarget
:
"
umd
"
,
library
:
"
librdf
"
,
umdNamedDefine
:
true
},
devtool
:
"
source-map
"
,
resolve
:
{
extensions
:
[
"
.ts
"
,
"
.tsx
"
,
"
.js
"
,
"
.json
"
]
},
module
:
{
rules
:
[
{
test
:
/
\.
tsx
?
$/
,
loader
:
"
ts-loader
"
},
{
enforce
:
"
pre
"
,
test
:
/
\.
js$/
,
loader
:
"
source-map-loader
"
}
]
}
}
];
libview/src/index.ts
View file @
c52b4cd1
...
...
@@ -21,5 +21,7 @@
import
*
as
application
from
"
./application
"
;
import
*
as
definition
from
"
./view-def
"
;
import
*
as
implementation
from
"
./view-impl
"
;
import
*
as
rdfEntities
from
"
./rdf-entities
"
;
import
*
as
rdfMeta
from
"
./rdf-meta
"
;
export
{
application
,
definition
,
implementation
};
export
{
application
,
definition
,
implementation
,
rdfEntities
,
rdfMeta
};
lib
rdf
/src/
index
.ts
→
lib
view
/src/
rdf-entities
.ts
View file @
c52b4cd1
...
...
@@ -19,45 +19,6 @@
******************************************************************************/
import
*
as
$rdf
from
"
rdflib
"
;
require
(
"
rdflib
"
);
/**
* Gets the value for the propert of a resource
* @param store The RDF store containing the data
* @param resource The resource
* @param property The property
*/
export
function
getValueOf
(
store
:
$rdf
.
Formula
,
resource
:
string
,
property
:
string
):
$rdf
.
Node
{
return
store
.
any
(
$rdf
.
sym
(
resource
),
$rdf
.
sym
(
property
),
undefined
,
undefined
);
}
/**
* Gets the values for the propert of a resource
* @param store The RDF store containing the data
* @param resource The resource
* @param property The property
*/
export
function
getValuesOf
(
store
:
$rdf
.
Formula
,
resource
:
string
,
property
:
string
):
$rdf
.
Node
[]
{
return
store
.
each
(
$rdf
.
sym
(
resource
),
$rdf
.
sym
(
property
),
undefined
,
undefined
);
}
/**
* A single RDF entity that may have aliases
...
...
libview/src/rdf-meta.ts
0 → 100644
View file @
c52b4cd1
/*******************************************************************************
* Copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
*
* This file is part of CubicWeb.
*
* CubicWeb is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 2.1 of the License, or (at your option)
* any later version.
*
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import
*
as
$rdf
from
"
rdflib
"
;
import
{
RdfEntity
,
RdfEntityStore
}
from
"
./rdf-entities
"
;
import
{
Language
,
ViewRenderer
,
RenderingContext
}
from
"
./application
"
;
/**
* Represents some ontological knowledge about a domain
*/
export
interface
Ontology
{
/**
* The known aliases
*/
aliases
:
string
[][];
/**
* The known inverse relations
*/
inverses
:
{
[
uri
:
string
]:
string
};
}
/**
* A resolver of objects from entities
*/
export
type
ObjectResolver
=
(
entity
:
RdfEntity
,
metaClass
:
MetaClass
)
=>
any
;
/**
* Represents the data about a property
*/
export
interface
MetaProperty
{
/**
* The associated property's URI
*/
readonly
uri
:
string
;
/**
* The property's name
*/
readonly
name
:
string
;
/**
* Whether the property is a vector property
*/
readonly
isVector
:
boolean
;
/**
* Whether the property is an object property
*/
readonly
isObject
:
boolean
;
/**
* Loads the value(s) of this property
* @param entity An entity
* @param languages The selected languages
* @param resolver The object resolver to use
*/
load
(
entity
:
RdfEntity
,
languages
:
Language
[],
resolver
:
ObjectResolver
):
any
;
}
/**
* Represents the meta data about a data property
*/
export
class
MetaPropertyData
implements
MetaProperty
{
/**
* The associated property's URI
*/
public
readonly
uri
:
string
;
/**
* The property's name
*/
public
readonly
name
:
string
;
/**
* Whether the property is a vector property
*/
public
readonly
isVector
:
boolean
;
/**
* Whether the property is an object property
*/
public
readonly
isObject
:
boolean
;
/**
* Initialies this property
* @param name The property's name
* @param uri The associated property's URI
* @param isVector Whether the property is a vector property
*/
constructor
(
name
:
string
,
uri
:
string
,
isVector
:
boolean
=
false
)
{
this
.
name
=
name
;
this
.
uri
=
uri
;
this
.
isVector
=
isVector
;
this
.
isObject
=
false
;
}
/**
* Loads the value(s) of this property
* @param entity An entity
* @param languages The selected languages
* @param resolver The object resolver to use
*/
public
load
(
entity
:
RdfEntity
,
languages
:
Language
[],
resolver
:
ObjectResolver
):
any
{
let
literals
=
entity
.
getValuesForS
(
this
.
uri
);
literals
=
literals
.
filter
((
node
:
$rdf
.
Node
)
=>
node
.
termType
==
"
Literal
"
);
if
(
literals
.
length
==
0
)
return
this
.
isVector
?
[]
:
null
;
let
matching
=
literals
.
filter
((
literal
:
$rdf
.
Literal
)
=>
{
for
(
var
l
=
0
;
l
!=
languages
.
length
;
l
++
)
{
if
(
literal
.
lang
==
languages
[
l
].
iso639_1
||
literal
.
lang
==
languages
[
l
].
iso639_2
)
return
true
;
}
return
false
;
})
.
map
((
literal
:
$rdf
.
Literal
)
=>
literal
.
value
);
if
(
matching
.
length
!=
0
)
return
this
.
isVector
?
matching
:
matching
[
0
];
return
this
.
isVector
?
literals
.
map
((
literal
:
$rdf
.
Literal
)
=>
literal
.
value
)
:
literals
[
0
].
value
;
}
}
/**
* Represents the meta data about an object property
*/
export
class
MetaPropertyObject
implements
MetaProperty
{
/**
* The associated property's URI
*/
public
readonly
uri
:
string
;
/**
* The property's name
*/
public
readonly
name
:
string
;
/**
* Whether the property is a vector property
*/
public
readonly
isVector
:
boolean
;
/**
* Whether the property is an object property
*/
public
readonly
isObject
:
boolean
;
/**
* The meta-class for the type of the property, if this is an object property
*/
public
readonly
metaClass
:
MetaClass
;
/**
* Initialies this property
* @param name The property's name
* @param uri The associated property's URI
* @param metaClass The meta-class for the type of the property, if this is an object property
* @param isVector Whether the property is a vector property
*/
constructor
(
name
:
string
,
uri
:
string
,
metaClass
:
MetaClass
,
isVector
:
boolean
=
false
)
{
this
.
name
=
name
;
this
.
uri
=
uri
;
this
.
metaClass
=
metaClass
;
this
.
isVector
=
isVector
;
this
.
isObject
=
true
;
}
/**
* Loads the value(s) of this property
* @param entity An entity
* @param languages The selected languages
* @param resolver The object resolver to use
*/
public
load
(
entity
:
RdfEntity
,
languages
:
Language
[],
resolver
:
ObjectResolver
):
any
{
let
result
=
entity
.
getEntitiesForS
(
this
.
uri
).
map
((
e
:
RdfEntity
)
=>
{
let
focus
=
e
.
getEntityForS
(
"
http://xmlns.com/foaf/0.1/focus
"
);
let
real
=
focus
!=
null
?
focus
:
e
;
return
resolver
(
real
,
this
.
metaClass
);
});
return
this
.
isVector
?
result
:
result
.
length
==
0
?
null
:
result
[
0
];
}
}
/**
* A metaclass that can be loaded from a dataset
*/
export
class
MetaClass
{
/**
* The class's meta properties
*/
public
properties
:
MetaProperty
[]
=
[];
/**
* Loads an instance of this metaclass from the specified entity
* @param entity An entity
* @param languages The selected languages
* @param result The resulting object
* @param resolver The object resolver to use
*/
public
loadProperties
(
entity
:
RdfEntity
,
languages
:
Language
[],
result
:
any
,
resolver
:
ObjectResolver
):
void
{
this
.
properties
.
forEach
((
property
:
MetaProperty
)
=>
{
result
[
property
.
name
]
=
property
.
load
(
entity
,
languages
,
resolver
);
});
}
}
/**
* A loading item
*/
class
Item
{
/**
* The entity to load
*/
entity
:
RdfEntity
;
/**
* The associated metaclass
*/
metaClass
:
MetaClass
;
/**
* The resulting object
*/
object
:
any
;
}
/**
* The loader of entities
*/
class
Loader
{
constructor
()
{
this
.
items
=
[];
this
.
resolve
=
this
.
resolve
.
bind
(
this
);
this
.
close
=
this
.
close
.
bind
(
this
);
}
/**
* The items
*/
items
:
Item
[];
/**
* Resolves an object from an entity and its meta-class
* @param entity An entity
* @param metaClass The associated meta-class
*/
resolve
(
entity
:
RdfEntity
,
metaClass
:
MetaClass
):
any
{
let
found
=
this
.
items
.
find
((
item
:
Item
)
=>
item
.
entity
===
entity
);
if
(
found
==
undefined
)
{
found
=
{
entity
:
entity
,
metaClass
:
metaClass
,
object
:
{
uri
:
entity
.
uris
[
0
]
}
};
this
.
items
.
push
(
found
);
}
return
found
.
object
;
}
/**
* Closes this loader
* @param languages The selected languages
*/
close
(
languages
:
Language
[]):
void
{
let
i
=
0
;
while
(
i
<
this
.
items
.
length
)
{
this
.
items
[
i
].
metaClass
.
loadProperties
(
this
.
items
[
i
].
entity
,
languages
,
this
.
items
[
i
].
object
,
this
.
resolve
);
i
++
;
}
}
}
/**
* Loads the data for the entity of interest
* @param renderer The current renderer
* @param context The current rendering context
* @param target The current RDF entity to be rendered
*/
export
function
loadEntity
<
T
>
(
renderer
:
ViewRenderer
,
context
:
RenderingContext
,
ontology
:
Ontology
,
metaClass
:
MetaClass
,
target
:
string
):
T
{
let
repo
=
new
RdfEntityStore
(
context
.
store
,
ontology
.
aliases
,
ontology
.
inverses
);
let
entity
=
repo
.
entityForUri
(
target
);
let
focus
=
entity
.
getEntityForS
(
"
http://xmlns.com/foaf/0.1/focus
"
);
if
(
focus
!=
null
)
entity
=
focus
;
let
loader
=
new
Loader
();
loader
.
resolve
(
entity
,
metaClass
);
loader
.
close
(
renderer
.
getLanguagesFor
(
context
,
target
));
return
loader
.
items
[
0
].
object
;
}
libview/src/view-impl.ts
View file @
c52b4cd1
...
...
@@ -104,6 +104,7 @@ function fetchImplementation(
resolver
(
descriptor
.
resourceMain
)
.
then
((
content
:
string
)
=>
{
let
EMBEDDED
=
IMPL_EMBEDDED
;
try
{
let
result
=
eval
(
content
);
if
(
result
==
null
||
result
==
undefined
)
{
reject
(
...
...
@@ -128,6 +129,9 @@ function fetchImplementation(
}
else
{
resolve
(
result
);
}
}
catch
(
e
)
{
reject
(
e
);
}
})
.
catch
((
reason
:
string
)
=>
{
reject
(
...
...
views-logilab/package.json
View file @
c52b4cd1
...
...
@@ -22,9 +22,7 @@
"author"
:
"LOGILAB <contact@logilab.fr>"
,
"license"
:
"LGPL-3.0"
,
"dependencies"
:
{
"@logilab/librdf"
:
"file:../librdf"
,
"@logilab/libview"
:
"file:../libview"
,
"rdflib"
:
"^0.17.0"
,
"vue"
:
"^2.5.16"
},
"devDependencies"
:
{
...
...
views-logilab/src/book/BookImpl.vue
View file @
c52b4cd1
...
...
@@ -6,10 +6,10 @@
<tr>
<td><b>
Authors
</b></td>
<td>
<div
v-for=
"
uri
in book.authors"
v-bind:key=
"uri"
class=
"card"
>
<div
v-for=
"
person
in book.authors"
v-bind:key=
"
person.
uri"
class=
"card"
>
<div
className=
"card-body"
>
<span>
Author:
</span>
<a
v-on:click=
"(event) =>
{event.preventDefault(); context.event.onRequestNavigateTo(uri);}" :href=
uri>
{{
uri
}}
</a>
<a
v-on:click=
"(event) =>
{event.preventDefault(); context.event.onRequestNavigateTo(
person.
uri);}" :href=
person.uri>
{{
person
.
name
!=
null
?
person
.
name
:
person
.
uri
}}
</a>
</div>
</div>
</td>
...
...
views-logilab/src/book/book.ts
View file @
c52b4cd1
...
...
@@ -18,18 +18,17 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import
{
RdfEntity
}
from
"
@logilab/librdf
"
;
import
{
application
,
definition
,
implementation
}
from
"
@logilab/libview
"
;
import
{
application
,
definition
,
implementation
,
rdfEntities
}
from
"
@logilab/libview
"
;
import
*
as
$rdf
from
"
rdflib
"
;
import
Vue
from
"
vue
"
;
/// <reference path="../common/vue.d.ts" />
import
BookImpl
from
"
./BookImpl.vue
"
;
import
{
MetaClass
,
MetaProperty
,
getMainEntity
,
loadEntity
}
from
"
../common/utils
"
;
import
{
ONTOLOGY
,
loadBook
,
Person
}
from
"
../common/schema
"
;
/**
* The descritptor for the default book view
...
...
@@ -53,30 +52,6 @@ const DESCRIPTOR_BOOK: definition.ViewDescriptor = {
}
as
definition
.
ViewResourceRemote
};
/**
* The data for a book
*/
interface
Book
{
authors
:
string
;
title
:
string
;
abstract
:
string
;
comment
:
string
;
publisher
:
string
;
releaseDate
:
string
;
}
/**
* The metaclass for Book