Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
126c430f
Commit
126c430f
authored
5 years ago
by
Bekerle, Patrizio
Committed by
Reiter, Christoph
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement support for reloading JSONLD after vpu-auth-init event
parent
81a1d80f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/common/jsonld.js
+73
-68
73 additions, 68 deletions
packages/common/jsonld.js
with
73 additions
and
68 deletions
packages/common/jsonld.js
+
73
−
68
View file @
126c430f
...
@@ -45,79 +45,84 @@ export default class JSONLD {
...
@@ -45,79 +45,84 @@ export default class JSONLD {
initStarted
[
apiUrl
]
=
true
;
initStarted
[
apiUrl
]
=
true
;
// window.VPUAuthToken will be set by on vpu-auth-init
if
(
window
.
VPUAuthToken
!==
undefined
)
{
window
.
addEventListener
(
"
vpu-auth-init
"
,
function
(
e
)
JSONLD
.
doInitialization
(
apiUrl
);
{
}
else
{
const
xhr
=
new
XMLHttpRequest
();
// window.VPUAuthToken will be set by vpu-auth-init event
xhr
.
open
(
"
GET
"
,
apiUrl
,
true
);
window
.
addEventListener
(
"
vpu-auth-init
"
,
()
=>
JSONLD
.
doInitialization
(
apiUrl
));
xhr
.
setRequestHeader
(
'
Authorization
'
,
'
Bearer
'
+
window
.
VPUAuthToken
);
}
}
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
&&
xhr
.
status
===
200
)
{
static
doInitialization
(
apiUrl
)
{
const
json
=
JSON
.
parse
(
xhr
.
responseText
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"
GET
"
,
apiUrl
,
true
);
let
entryPoints
=
{};
xhr
.
setRequestHeader
(
'
Authorization
'
,
'
Bearer
'
+
window
.
VPUAuthToken
);
for
(
let
property
in
json
)
{
// for some reason the properties start with a lower case character
xhr
.
onreadystatechange
=
function
()
{
if
(
!
property
.
startsWith
(
"
@
"
))
entryPoints
[
property
.
toLowerCase
()]
=
json
[
property
];
if
(
xhr
.
readyState
===
4
&&
xhr
.
status
===
200
)
{
}
const
json
=
JSON
.
parse
(
xhr
.
responseText
);
// read the link header of the api response
let
entryPoints
=
{};
// const utils = require("./utils");
for
(
let
property
in
json
)
{
const
links
=
utils
.
parseLinkHeader
(
this
.
getResponseHeader
(
"
link
"
));
// for some reason the properties start with a lower case character
if
(
!
property
.
startsWith
(
"
@
"
))
entryPoints
[
property
.
toLowerCase
()]
=
json
[
property
];
// get the hydra apiDocumentation url
}
const
apiDocUrl
=
links
[
"
http://www.w3.org/ns/hydra/core#apiDocumentation
"
];
// read the link header of the api response
if
(
apiDocUrl
!==
undefined
)
{
// const utils = require("./utils");
// load the hydra apiDocumentation
const
links
=
utils
.
parseLinkHeader
(
this
.
getResponseHeader
(
"
link
"
));
const
docXhr
=
new
XMLHttpRequest
();
docXhr
.
open
(
"
GET
"
,
apiDocUrl
,
true
);
// get the hydra apiDocumentation url
docXhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
const
apiDocUrl
=
links
[
"
http://www.w3.org/ns/hydra/core#apiDocumentation
"
];
docXhr
.
onreadystatechange
=
function
()
{
if
(
docXhr
.
readyState
===
4
&&
docXhr
.
status
===
200
)
{
if
(
apiDocUrl
!==
undefined
)
{
const
json
=
JSON
.
parse
(
docXhr
.
responseText
);
// load the hydra apiDocumentation
const
supportedClasses
=
json
[
"
hydra:supportedClass
"
];
const
docXhr
=
new
XMLHttpRequest
();
docXhr
.
open
(
"
GET
"
,
apiDocUrl
,
true
);
let
entities
=
{};
docXhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
const
baseUrl
=
utils
.
parseBaseUrl
(
apiUrl
);
docXhr
.
onreadystatechange
=
function
()
{
if
(
docXhr
.
readyState
===
4
&&
docXhr
.
status
===
200
)
{
// gather the entities
const
json
=
JSON
.
parse
(
docXhr
.
responseText
);
supportedClasses
.
forEach
(
function
(
classData
)
{
const
supportedClasses
=
json
[
"
hydra:supportedClass
"
];
// add entry point url
const
entityName
=
classData
[
"
hydra:title
"
];
let
entities
=
{};
let
entryPoint
=
entryPoints
[
entityName
.
toLowerCase
()];
const
baseUrl
=
utils
.
parseBaseUrl
(
apiUrl
);
if
(
entryPoint
!==
undefined
&&
!
entryPoint
.
startsWith
(
"
http
"
))
entryPoint
=
baseUrl
+
entryPoint
;
classData
[
"
@entryPoint
"
]
=
entryPoint
;
// gather the entities
supportedClasses
.
forEach
(
function
(
classData
)
{
entities
[
entityName
]
=
classData
;
// add entry point url
});
const
entityName
=
classData
[
"
hydra:title
"
];
let
entryPoint
=
entryPoints
[
entityName
.
toLowerCase
()];
const
instance
=
new
JSONLD
(
baseUrl
,
entities
);
if
(
entryPoint
!==
undefined
&&
!
entryPoint
.
startsWith
(
"
http
"
))
entryPoint
=
baseUrl
+
entryPoint
;
instances
[
apiUrl
]
=
instance
;
classData
[
"
@entryPoint
"
]
=
entryPoint
;
// return the initialized JSONLD object
entities
[
entityName
]
=
classData
;
for
(
const
fnc
of
successFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
(
instance
);
});
successFunctions
[
apiUrl
]
=
[];
}
else
{
const
instance
=
new
JSONLD
(
baseUrl
,
entities
);
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
instances
[
apiUrl
]
=
instance
;
failureFunctions
[
apiUrl
]
=
[];
}
// return the initialized JSONLD object
};
for
(
const
fnc
of
successFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
(
instance
);
successFunctions
[
apiUrl
]
=
[];
docXhr
.
send
();
}
else
{
}
else
{
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
failureFunctions
[
apiUrl
]
=
[];
failureFunctions
[
apiUrl
]
=
[];
}
}
};
docXhr
.
send
();
}
else
{
}
else
{
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
failureFunctions
[
apiUrl
]
=
[];
failureFunctions
[
apiUrl
]
=
[];
}
}
};
}
else
{
for
(
const
fnc
of
failureFunctions
[
apiUrl
])
if
(
typeof
fnc
==
'
function
'
)
fnc
();
failureFunctions
[
apiUrl
]
=
[];
}
};
xhr
.
send
();
xhr
.
send
();
});
}
}
static
getInstance
(
apiUrl
)
{
static
getInstance
(
apiUrl
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment