Skip to content

Commit

Permalink
BDE-226 fixing-up document browsing (json tab included)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Mar 11, 2024
1 parent ce089ef commit 34cb624
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/document-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DocumentBrowser {
this.worker = worker;

// Bind methods
this.jsonOf = this.jsonOf.bind(this);
this.openDocument = this.openDocument.bind(this);
this.openDocFromId = this.openDocFromId.bind(this);
this.openDocFromPath = this.openDocFromPath.bind(this);
Expand Down Expand Up @@ -130,7 +131,7 @@ class DocumentBrowser {
});
}

getJson(repository, path) {
jsonOf(repository, path) {
return this.worker.serverConnector.withNuxeo()
.then((nuxeo) => nuxeo
.request(`/repo/${repository}/${path}`)
Expand Down
9 changes: 6 additions & 3 deletions src/main/json-highlighter.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
class JsonHighlighter {
// eslint-disable-next-line no-unused-vars
constructor(worker) {
this.inpur = '';
this._input = '';

// Bind methods
this.input = this.input.bind(this);
}

input(input) {
if (input) {
this.input = input;
this._input = input;
}
return new Promise((resolve, reject) => {
if (!this.input) {
reject(new Error('No json input text provided'));
}
resolve(this.input);
resolve(this._input);
});
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,26 @@ class ServerConnector {
}));
}

query(schemas = ['dublincore', 'common', 'uid'], query) {
query(input, schemas = ['dublincore', 'common', 'uid']) {
return Promise.all([this.runtimeInfo(), this.withNuxeo()])
.then(([runtimeInfo, nuxeo]) => {
const username = runtimeInfo.nuxeo._auth.username;
const userid = runtimeInfo.nuxeo.user.id;
const defaultSelectClause = '* FROM Document';
const defaultWhereClause = `ecm:path STARTSWITH "/default-domain/UserWorkspaces/${username}"`;
const defaultWhereClause = `ecm:path STARTSWITH "/default-domain/UserWorkspaces/${userid}"`;
const defaultQuery = `SELECT ${defaultSelectClause} WHERE ${defaultWhereClause}"`;
const sortBy = query && query.sortBy ? query.sortBy : 'dc:modified DESC';
const defaultSortBy = 'dc:modified DESC';

if (!query || (typeof query === 'object' && !query.query)) {
query = defaultQuery;
if (!input || (typeof input === 'object' && !input.query)) {
input.query = defaultQuery;
}
if (!input.sortBy) {
input.sortBy = defaultSortBy;
}

return nuxeo
.repository()
.schemas(schemas)
.query({ query, sortBy });
.query(input);
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function loadPage(serviceWorker) {
function doGetJson(path) {
serviceWorker.browserStore.get({ highlight: true }).then((res) => {
if (res.highlight) {
serviceWorker.documentBrowser.getJsonFromPath(repository, path)
serviceWorker.documentBrowser.jsonOf(repository, path)
.then(openJsonWindow);
} else {
const jsonPath = `api/v1/repo/${repository}/${path}?enrichers.document=acls,permissions&properties=*`;
Expand Down Expand Up @@ -591,13 +591,13 @@ function loadPage(serviceWorker) {
$('table').css('margin-top', '20px');
res.entries.forEach((doc) => {
$('html').outerHeight($('html').height());
const icon = doc.get('common:icon');
const title = doc.get('dc:title');
const icon = doc.properties['common:icon'];
const title = doc.properties['dc:title'];
const re = /^(.*[\/])/;
const path = re.exec(doc.path)[1];
const uid = doc.uid;
const vMajor = doc.get('uid:major_version');
const vMinor = doc.get('uid:minor_version');
const vMajor = doc.properties['uid:major_version'];
const vMinor = doc.properties['uid:minor_version'];
showSearchResults(icon, title, path, uid, vMajor, vMinor);
});
$('.doc-title').click((event) => {
Expand Down Expand Up @@ -633,7 +633,7 @@ function loadPage(serviceWorker) {
let openJsonWindow = (jsonObject) => {
const jsonString = JSON.stringify(jsonObject, undefined, 2);
serviceWorker.jsonHighlighter.input(DOMPurify.sanitize(jsonString));
serviceWorker.serverLocator.loadNewExtensionTab('json.html');
serviceWorker.serverLocator.loadNewExtensionTab('json/index.html');
};

$('#restart-button').on('click', () => {
Expand Down

0 comments on commit 34cb624

Please sign in to comment.