Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update refinery.js and minify #63

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions static/js/refinery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ window.refinery = window.refinery || {};

refinery.RefineryAPI = function (config = {}) {
this.storage = window.localStorage;
this.refineryApikey = this.getApiKeyFromScriptTag();
this.refineryAppToken = this.getAppTokenFromScriptTag();

let defaultConfig = {
debugMode: false,
refineryHostUrl: "https://app.banditml.com/api/v2",
refineryHostUrl: "https://app.banditml.com/api/v2/",
};
this.config = Object.assign(defaultConfig, config);

this.refineryLiveRefinementEndpoint = `${this.config.refineryHostUrl}changesets`;
};

refinery.RefineryAPI.prototype.getApiKeyFromScriptTag = function () {
return document.currentScript.getAttribute('apiKey');
refinery.RefineryAPI.prototype.getAppTokenFromScriptTag = function () {
return document.currentScript.getAttribute('appToken');
};

refinery.RefineryAPI.prototype.asyncGetRequest = async function(
Expand Down Expand Up @@ -53,7 +53,7 @@ refinery.RefineryAPI.prototype.getLiveRefinement = function() {
url = self.refineryLiveRefinementEndpoint,
params = {},
headers = {
"x-chrome-installation": `${self.refineryApikey}`
"x-app-token": `${self.refineryAppToken}`
}
);
return changesPromise.then(response => {
Expand All @@ -67,8 +67,11 @@ refinery.RefineryAPI.prototype.applyChanges = function() {
const self = this;
self.getLiveRefinement().then(response => {
// right now we assume 1 changeset only, so grab the first i.e. [0]
let changes = response[0].changes;
changes.forEach(change => {
let changeset = response[0];
let changes;
(changeset.publish) ? changes = changeset.changes : changes = [];

changes.filter(change => !change.deleted).forEach(change => {
if (window.location.href === change.href) {
let elem = document.querySelector(change.domPath);
if (elem.innerHTML !== change.beforeHtml) {
Expand Down
1 change: 1 addition & 0 deletions static/minified/refinery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Welcome</title>
<link rel="stylesheet" href={{ url_for('static', filename='css/home.css') }} />
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css') }} />
<script src={{ url_for('static', filename='js/refinery.js')}} defer="defer" apiKey="a6a0c233-988b-4d6f-b940-bab1573aef95"></script>
<script src={{ url_for('static', filename='js/refinery.js')}} defer="defer" appToken="ad182d5c-4ad7-48f8-98a3-cf29067a58b4"></script>
</head>
<body>
<div id="title">
Expand Down