Skip to content

Commit

Permalink
Update bfe code to handle profile data structure as provided by Verso.
Browse files Browse the repository at this point in the history
Resolves #13.
  • Loading branch information
wafschneider committed Jun 22, 2018
1 parent 22db37f commit 1a2226b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 43 deletions.
29 changes: 21 additions & 8 deletions builds/bfe.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,36 @@ bfe.define('src/bfe', ['require', 'exports', 'module', 'src/bfestore', 'src/bfel
// Set up logging
bfelog.init(editorconfig);

/**
* Profiles are expected to be in the form provided by Verso:
* A JSON Array of objects with a "json" property that contains the profile proper
**/
for (var i = 0; i < config.profiles.length; i++) {
var file = config.profiles[i];
bfelog.addMsg(new Error(), 'INFO', 'Loading profile: ' + config.profiles[i]);
$.ajax({
type: 'GET',
dataType: 'json',
url: file,
success: function (data) {
$('#bfeditor-loader').width($('#bfeditor-loader').width() + 5 + '%');
profiles.push(data);
for (var rt = 0; rt < data.Profile.resourceTemplates.length; rt++) {
resourceTemplates.push(data.Profile.resourceTemplates[rt]);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
bfelog.addMsg(new Error(), 'ERROR', 'FAILED to load profile: ' + file);
bfelog.addMsg(new Error(), 'ERROR', 'Request status: ' + textStatus + '; Error msg: ' + errorThrown);
},
complete: function (jqXHR, textStatus) {
if (textStatus == 'success') {
var data = JSON.parse(jqXHR.responseText);
$('#bfeditor-loader').width($('#bfeditor-loader').width() + 5 + '%');
if (data.length > 0) {
for (var j = 0; j < data.length; j++) {
profiles.push(data[j].json);
for (var rt = 0; rt < data[j].json.Profile.resourceTemplates.length; rt++) {
resourceTemplates.push(data[j].json.Profile.resourceTemplates[rt]);
}
bfelog.addMsg(new Error(), 'INFO', 'Loaded profile: ' + data[j].name);
}
} else {
bfelog.addMsg(new Error(), 'ERROR', 'No profiles loaded from ' + this.url + ' (empty result set)');
}
}
}
});
}
Expand Down
19 changes: 18 additions & 1 deletion docs/bfe-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,24 @@ callback function for when the user hits the `save` button.
#### `config` Properties

Required
* `profiles`: (Array) location of Profiles to be loaded.
* `profiles`: (Array) locations (URLs) of Profiles to be
loaded. Profiles should be in the form of a JSON array with one or
more objects that contain a "name" and a "json" property with the
profile itself. For example:

```json
[
{
"name": "BIBFRAME 2.0 Agent",
"json": {
"Profile": {
[...]
}
}
}
]
```

* `return`: (Object) contains two properties. `format`, which indicates how the
the data should be formatted/serialized. Only "jsonld-expanded" is supported
presently. `callback` is the name of the callback function, which expects one
Expand Down
78 changes: 44 additions & 34 deletions static/js/config-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ function deleteId(id, csrf, bfelog){

}

/* Config object profiles
* Editor profiles are read from a WS endpoint
* The data are expected to be in a JSON array, with each object
* in the array containing a "json" property that has the profile
* itself. The "versoURL" variable is a convenience for setting the
* base URL of verso in the "config" definition below.
*/

var versoURL = "http://mlvlp04.loc.gov:3000/verso/api";
// var versoURL = "/verso/api";
//var versoURL = "/verso/api";
var config = {
/* "logging": {
"level": "DEBUG",
Expand All @@ -230,39 +238,41 @@ var config = {
"basedbURI": "http://mlvlp04.loc.gov:8230",
"resourceURI": "http://mlvlp04.loc.gov:8230/resources",
"profiles": [
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Agents.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Agents Contribution.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Agents Primary Contribution.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Form.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Language.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 LCC.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Notated Music.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Place.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Publication, Distribution, Manufacturer Activity.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Related Works and Expressions.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Topic.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Serial.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Monograph.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Admin Metadata.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Cartographic.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Sound Recording: Analog.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Sound Recording: Audio CD.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Sound Recording: Audio CD-R.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Moving Image: BluRay DVD.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Moving Image: 35mm Feature Film.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Prints and Photographs.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 RWO.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Title Information.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Edition Information.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Series Information.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 DDC.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Item.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Identifiers.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Note.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Rare Materials.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Sound Recording: Audio CD-R.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 Load.json",
versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=/BIBFRAME 2.0 IBC.json"
versoURL + "/configs?filter[where][configType]=profile"
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Admin Metadata",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Agents Contribution",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Agents Primary Contribution",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Agents",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Cartographic",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 DDC",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Edition Information",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Form",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 IBC",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Identifiers",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Item",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 LCC",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Language",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Load",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Monograph",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Moving Image-35mm Feature Film",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Moving Image-BluRay DVD",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Notated Music",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Note",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Place",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Prints and Photographs",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Publication, Distribution, Manufacturer Activity",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 RWO",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Rare Materials",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Related Works and Expressions",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Serial",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Series Information",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Sound Recording-Analog",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Sound Recording-Audio CD-R",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Sound Recording-Audio CD",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Title Information",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=BIBFRAME 2.0 Topic",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=PMO Medium of Performance",
// versoURL + "/configs?filter[where][configType]=profile&filter[where][name]=Test BSR monograph"
],
"startingPoints": [
{"menuGroup": "Monograph",
Expand Down

0 comments on commit 1a2226b

Please sign in to comment.