Skip to content

Commit

Permalink
SAK-41453 Added rubrics paging back in (sakaiproject#6625)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Mar 8, 2019
1 parent 7778a5e commit 0234b0b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SakaiRubricReadonly extends SakaiElement {
<div class="actions">
<div class="action-container">
<span class="hidden-sm hidden-xs sr-only"><sr-lang key="clone_label">clone_label</sr-lang> </span>
<span role="button" title="${tr("clone")} ${this.rubric.title}" tabindex="0" class="clone fa fa-copy" on-tap="cloneRubric"></span>
<span role="button" title="${tr("clone")} ${this.rubric.title}" tabindex="0" class="clone fa fa-copy" @click="${this.copyToSite}"></span>
</div>
</div>
</div>
Expand Down Expand Up @@ -84,7 +84,7 @@ export class SakaiRubricReadonly extends SakaiElement {
copyToSite(e) {

e.stopPropagation();
this.dispatchEvent(new CustomEvent('copy-to-site', { detail: this.rubric }));
this.dispatchEvent(new CustomEvent('copy-to-site', { detail: this.rubric.id }));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,40 @@ export class SakaiRubricsHelpers {
return response;
}

static get(url, token, contentType = "application/json") {
static get(url, token, extraOptions) {

if (extraOptions.params) {
var usp = new URLSearchParams();
Object.entries(extraOptions.params).forEach(([k,v]) => usp.append(k,v));
url += `?${usp.toString()}`;
}

var options = {
method: "GET",
headers: {
"Authorization": token,
"Accept": "application/json",
"Content-Type": contentType,
"Content-Type": "application/json",
}
};

Object.assign(options.headers, extraOptions.extraHeaders);

return fetch(url, options).then(SakaiRubricsHelpers.handleErrors).then(response => response.json());
}

static post(url, extraOptions) {
static post(url, token, extraOptions) {

var body
= extraOptions.body ? Object.entries(extraOptions.body).reduce((acc, [k,v]) => acc.append(k,v), new FormData())
: "{}";

var options = {
method: "POST",
headers: { "Content-Type": "application/json", "Authorization": extraOptions.token },
headers: {
"Authorization": token,
"Content-Type": "application/json",
},
body: body,
};

Expand Down
23 changes: 17 additions & 6 deletions rubrics/tool/src/main/frontend/webcomponents/sakai-rubrics-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,23 @@ export class SakaiRubricsList extends SakaiElement {
`;
}

getRubrics(token) {
refresh() {
this.getRubrics(this.token);
}

getRubrics(token, extraParams = {}) {

var params = {"projection": "inlineRubric"};
Object.assign(params, extraParams);

SakaiRubricsHelpers.get("/rubrics-service/rest/rubrics?projection=inlineRubric", this.token)
SakaiRubricsHelpers.get("/rubrics-service/rest/rubrics", token, { params })
.then(data => {

this.rubrics = data._embedded.rubrics;

if (data.page.size <= this.rubrics.length){
this.getRubrics(token, { "size": this.rubrics.length + 25 });
}
});
}

Expand All @@ -71,6 +83,7 @@ export class SakaiRubricsList extends SakaiElement {
this.rubrics = tmp;

this.requestUpdate();
this.updateComplete.then(() => { this.querySelector(`#rubric_item_${nr.id} sakai-rubric`).toggleRubric(); });
}

deleteRubric(e) {
Expand All @@ -89,17 +102,15 @@ export class SakaiRubricsList extends SakaiElement {

cloneRubric(e) {

SakaiRubricsHelpers.post("/rubrics-service/rest/rubrics/", {
token: this.token,
SakaiRubricsHelpers.post("/rubrics-service/rest/rubrics/", this.token, {
extraHeaders: {"x-copy-source": e.detail.id, "lang": portal.locale}
})
.then(data => this.createRubricResponse(data));
}

createNewRubric() {

SakaiRubricsHelpers.post("/rubrics-service/rest/rubrics/", {
token: this.token,
SakaiRubricsHelpers.post("/rubrics-service/rest/rubrics/", this.token, {
extraHeaders: {"x-copy-source" :"default", "lang": portal.locale}
})
.then(data => this.createRubricResponse(data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SakaiRubricsManager extends SakaiElement {
<div role="tabpanel" aria-labelledby="shared-rubrics-title" id="shared_rubrics">
<div id="sharedlist">
<sakai-rubrics-shared-list token="Bearer ${this.token}" id="sakai-rubrics-shared-list"></sakai-rubrics-shared-list>
<sakai-rubrics-shared-list token="Bearer ${this.token}" id="sakai-rubrics-shared-list" @copy-share-site="${this.copyShareSite}" ></sakai-rubrics-shared-list>
</div>
</div>
Expand All @@ -70,7 +70,7 @@ class SakaiRubricsManager extends SakaiElement {
}

copyShareSite() {
this.querySelector("sakai-rubrics-list").ready();
this.querySelector("sakai-rubrics-list").refresh();
}

toggleSiteRubrics() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {SakaiElement} from "/webcomponents/sakai-element.js";
import {html} from "/webcomponents/assets/lit-element/lit-element.js";
import {SakaiRubricReadonly} from "./sakai-rubric-readonly.js";
import {SakaiRubricsHelpers} from "./sakai-rubrics-helpers.js";

export class SakaiRubricsSharedList extends SakaiElement {

constructor() {

super();

this.rubrics = [];
}

static get properties() {

return {
Expand All @@ -24,52 +18,44 @@ export class SakaiRubricsSharedList extends SakaiElement {
super.attributeChangedCallback(name, oldValue, newValue);

if ("token" === name) {
this.getSharedRubrics();
this.getSharedRubrics(newValue);
}
}

shouldUpdate(changedProperties) {
return changedProperties.has("rubrics");
}

render() {

return html`
<div role="tablist">
${this.rubrics.map(r => html`
<div class="rubric-item" id="rubric_item_${r.id}">
<sakai-rubric-readonly token="${this.token}" rubric="${JSON.stringify(r)}"></sakai-rubric-readonly>
<sakai-rubric-readonly token="${this.token}" rubric="${JSON.stringify(r)}" @copy-to-site="${this.copyToSite}"></sakai-rubric-readonly>
</div>
`)}
</div>
`;
}

refresh() {
this.getSharedRubrics();
this.getSharedRubrics(this.token);
}

getSharedRubrics() {
getSharedRubrics(token) {

$.ajax({
url: "/rubrics-service/rest/rubrics/search/shared-only?projection=inlineRubric",
headers: {"authorization": this.token}
})
.done(data => {
var params = {"projection": "inlineRubric"};

this.rubrics = data._embedded.rubrics;
this.requestUpdate();
})
.fail((jqXHR, textStatus, error) => { console.log(textStatus); console.log(error); });
SakaiRubricsHelpers.get("/rubrics-service/rest/rubrics/search/shared-only", token, { params })
.then(data => this.rubrics = data._embedded.rubrics );
}

copyShareToSite(e) {

$.ajax({
url: "/rubrics-service/rest/rubrics/",
headers: { "x-copy-source": e.detail.id, "authorization": this.token },
contentType: "application/json",
method: "POST",
data: "{}"
})
.done(data => this.dispatchEvent(new CustomEvent('copy-share-site')) )
.fail((jqXHR, textStatus, error) => { console.log(textStatus); console.log(error); });
copyToSite(e) {

var options = { extraHeaders: { "x-copy-source": e.detail, "lang": portal.locale } };
SakaiRubricsHelpers.post("/rubrics-service/rest/rubrics/", this.token, options)
.then(data => this.dispatchEvent(new CustomEvent("copy-share-site")));
}
}

Expand Down

0 comments on commit 0234b0b

Please sign in to comment.