Commit 7ca3345d authored by Élodie Thiéblin's avatar Élodie Thiéblin
Browse files

feat: add a logigraphe project view

parent e4f627625484
Pipeline #32185 passed with stages
in 2 minutes and 41 seconds
[
{
"identifier": "::Logilab::Person",
"name": "Logilab: Person View",
"description": "Renders a person from a (possibly FoaF) dataset",
"entrypoint": "VIEW_PERSON_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_person.js"
{
"identifier": "::Logilab::Person",
"name": "Logilab: Person View",
"description": "Renders a person from a (possibly FoaF) dataset",
"entrypoint": "VIEW_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_person.js"
}
},
{
"identifier": "::Logilab::Book",
"name": "Logilab: Book View",
"description": "Renders a book from a dataset",
"entrypoint": "VIEW_BOOK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_book.js"
}
},
{
"identifier": "::Logilab::Conference",
"name": "Logilab: Conference View",
"description": "Renders a conference from a dataset",
"entrypoint": "VIEW_CONFERENCE_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_conference.js"
}
},
{
"identifier": "::Logilab::ConferenceTrack",
"name": "Logilab: Conference Track View",
"description": "Renders a conference track from a dataset",
"entrypoint": "VIEW_TRACK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_track.js"
}
},
{
"identifier": "::Logilab::ConferenceTalk",
"name": "Logilab: Conference Talk View",
"description": "Renders a conference talk from a dataset",
"entrypoint": "VIEW_TALK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_talk.js"
}
},
{
"identifier": "::Logilab::BlogPost",
"name": "Logilab: BlogPost View",
"description": "Renders a blog post",
"entrypoint": "VIEW_BLOGPOST_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_blogpost.js"
}
},
{
"identifier": "::Logilab::Blog",
"name": "Logilab: Blog View",
"description": "Renders a blog",
"entrypoint": "VIEW_BLOG_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_blog.js"
}
},
{
"identifier": "::Logilab::DublinCoreElement",
"name": "Logilab: Dublin Core Element View",
"description": "Renders a DublinCore Element",
"entrypoint": "VIEW_ENTRYPOINT",
"resourceCss": [
{
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"uri": "http://localhost:8080/view_dcelement.js"
}
},
{
"identifier": "::Logilab::Project",
"name": "Logilab: Project View",
"description": "Renders a project",
"entrypoint": "VIEW_ENTRYPOINT",
"resourceCss": [],
"resourceJs": [],
"resourceMain": {
"uri": "http://localhost:8080/view_project.js"
}
}
},
{
"identifier": "::Logilab::Book",
"name": "Logilab: Book View",
"description": "Renders a book from a dataset",
"entrypoint": "VIEW_BOOK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_book.js"
}
},
{
"identifier": "::Logilab::Conference",
"name": "Logilab: Conference View",
"description": "Renders a conference from a dataset",
"entrypoint": "VIEW_CONFERENCE_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_conference.js"
}
},
{
"identifier": "::Logilab::ConferenceTrack",
"name": "Logilab: Conference Track View",
"description": "Renders a conference track from a dataset",
"entrypoint": "VIEW_TRACK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_track.js"
}
},
{
"identifier": "::Logilab::ConferenceTalk",
"name": "Logilab: Conference Talk View",
"description": "Renders a conference talk from a dataset",
"entrypoint": "VIEW_TALK_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_talk.js"
}
},
{
"identifier": "::Logilab::BlogPost",
"name": "Logilab: BlogPost View",
"description": "Renders a blog post",
"entrypoint": "VIEW_BLOGPOST_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_blogpost.js"
}
},
{
"identifier": "::Logilab::Blog",
"name": "Logilab: Blog View",
"description": "Renders a blog",
"entrypoint": "VIEW_BLOG_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_blog.js"
}
},
{
"identifier": "::Logilab::DublinCoreElement",
"name": "Logilab: Dublin Core Element View",
"description": "Renders a DublinCore Element",
"entrypoint": "VIEW_ENTRYPOINT",
"resourceCss": [
{
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"uri": "http://localhost:8080/view_dcelement.js"
}
}
]
......@@ -32,7 +32,7 @@ const DESCRIPTOR_PERSON: definition.ViewDescriptor = {
identifier: '::Logilab::Person',
name: 'Logilab: Person View',
description: 'Renders a person from a (possibly FoaF) dataset',
entrypoint: 'VIEW_PERSON_ENTRYPOINT',
entrypoint: 'VIEW_ENTRYPOINT',
resourceCss: [
{
uri: 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css',
......@@ -57,7 +57,6 @@ class PersonRendering implements implementation.ViewImplementation {
let entity = repo.entityForUri(target.uri);
let focus = entity.getEntityForS('http://xmlns.com/foaf/0.1/focus');
if (focus !== null) entity = focus;
let entityTypes = entity.getEntitiesForS('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
if (entityTypes.length > 0) {
let x = entityTypes.find(
......@@ -122,3 +121,4 @@ class PersonRendering implements implementation.ViewImplementation {
* Export the view
*/
export const VIEW_PERSON_ENTRYPOINT: PersonRendering = new PersonRendering();
export const VIEW_ENTRYPOINT = VIEW_PERSON_ENTRYPOINT;
/*******************************************************************************
* 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 React from 'react';
import * as ReactDOM from 'react-dom';
import { application, definition, implementation, rdfEntities } from '@logilab/libview';
import * as $rdf from 'rdflib';
export const LibviewContext = React.createContext<{
generateUrl: (uri: string) => string;
sparqlendpoint?: string;
}>({ generateUrl: (uri) => uri });
export const DOAP = $rdf.Namespace('http://usefulinc.com/ns/doap#');
export const RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
export const LGG = $rdf.Namespace('http://data.logilab.fr/logigraphe/');
/**
* The descritptor for the default Dbpedia person view
*/
const DESCRIPTOR_PROJECT: definition.ViewDescriptor = {
identifier: '::Logilab::Project',
name: 'Logilab: Project View',
description: 'Renders a project',
entrypoint: 'VIEW_ENTRYPOINT',
resourceCss: [],
resourceJs: [],
resourceMain: {
uri: 'http://localhost:8080/view_project.js',
},
};
interface ProjectProps {
uri: string;
labels: string[];
badges: string[];
}
const Project: React.FC<ProjectProps> = ({ uri, labels, badges }) => (
<>
<h2>{labels[0]}</h2>
<ul>
{badges.map((badge) => (
<li>{badge}</li>
))}
</ul>
</>
);
class ProjectRendering implements implementation.ViewImplementation {
descriptor: definition.ViewDescriptor = DESCRIPTOR_PROJECT;
priorityFor(context: $rdf.Formula, target: application.Resource): number {
const targetSym = $rdf.sym(target.uri);
// this view is not suitable if it is not a doap:Project
if (context.whether(targetSym, RDF('type'), DOAP('Project')) === 0) return -1;
return 10;
}
render(
renderer: application.ViewRenderer,
context: application.RenderingContext,
target: application.Resource
): implementation.ViewRendering {
return {
dom: this.simpleRender('TODO', context.store, target.uri),
suggestedResources: [],
};
}
getBadges(context: $rdf.Formula, target: string): string[] {
let badges = [];
const targetSym = $rdf.sym(target);
if (context.whether(targetSym, LGG('has_black'), new $rdf.Literal('true')) !== 0) {
badges.push('black');
}
if (context.whether(targetSym, LGG('has_doc'), new $rdf.Literal('true')) !== 0) {
badges.push('doc');
}
if (context.whether(targetSym, LGG('has_flake8'), new $rdf.Literal('true')) !== 0) {
badges.push('flake8');
}
if (context.whether(targetSym, LGG('has_check_manifest'), new $rdf.Literal('true')) !== 0) {
badges.push('check manifest');
}
if (context.whether(targetSym, LGG('has_from_forge'), new $rdf.Literal('true')) !== 0) {
badges.push('from forge');
}
if (context.whether(targetSym, LGG('has_gitlab_ci'), new $rdf.Literal('true')) !== 0) {
badges.push('gitlab ci');
}
if (context.whether(targetSym, LGG('has_py3_test'), new $rdf.Literal('true')) !== 0) {
badges.push('py3');
}
return badges;
}
simpleRender(
nodeId: string,
context: $rdf.Formula,
target: string,
dataFetcher?: implementation.DataFetcher,
generateUrl?: (uri: string) => string,
sparqlendpoint?: string
): Element {
const targetSym = $rdf.sym(target);
const project: ProjectProps = {
uri: target,
labels: context.each(targetSym, DOAP('name'), null).map((node) => node.value),
badges: this.getBadges(context, target),
};
const domElement = document.getElementById(nodeId) ?? document.createElement('div');
ReactDOM.render(
<LibviewContext.Provider value={{ generateUrl: generateUrl ?? ((uri) => uri), sparqlendpoint }}>
<Project {...project} />
</LibviewContext.Provider>,
domElement
);
return domElement;
}
}
/**
* Export the view
*/
export const PROJECT_ENTRYPOINT: ProjectRendering = new ProjectRendering();
export const VIEW_ENTRYPOINT = PROJECT_ENTRYPOINT;
......@@ -14,6 +14,7 @@ module.exports = [
blogpost: "./src/blogpost/blogpost.tsx",
blog: "./src/blogpost/blog.tsx",
dcelement: "./src/dublincore/dublincore.tsx",
project: "./src/project/project.tsx",
},
mode: isProd ? "production" : "development",
output: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment