Skip to content

Commit

Permalink
Merge pull request #35 from mishani0x0ef/#29_error_in_console_for_non…
Browse files Browse the repository at this point in the history
…_jira_pages

#29 error in console for non jira pages
  • Loading branch information
mishani0x0ef authored Nov 4, 2017
2 parents aae0420 + e2fc9d5 commit db09fc2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
26 changes: 26 additions & 0 deletions ReportJ.Extension.Chrome/app/js/content/common/jiraUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Identify is current page Jira, based on it's content.
*/
export function checkIsInsideJira() {
return new Promise((resolve) => {
const acceptableStates = ["loaded", "interactive", "complete"];
const alreadyLoaded = acceptableStates.includes(document.readyState);

if (alreadyLoaded) {
const inJira = checkIsDocumentHasJiraMarkers();
resolve(inJira);
} else {
document.addEventListener("DOMContentLoaded", () => {
const inJira = checkIsDocumentHasJiraMarkers();
resolve(inJira);
});
}
});
}

function checkIsDocumentHasJiraMarkers() {
const jiraBodyId = "jira";
const bodyId = document.body.id || "";

return jiraBodyId === bodyId.toLowerCase();
}
27 changes: 8 additions & 19 deletions ReportJ.Extension.Chrome/app/js/content/content.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@

import AutoIssueSumaryExtender from "./autoIssueSummary/autoIssueSummaryExtender";
import CloseIssueExtender from "./closeIssue/closeIssueExtender";
import JiraWrapper from "~/js/services/jira";
import StorageService from "~/js/services/storageService";
import UrlService from "~/js/services/urlService";

import { checkIsInsideJira } from "~/js/content/common/jiraUtil";

class ContentController {
constructor(browser) {
const storage = new StorageService(browser);
const urlService = new UrlService(browser);
const baseUrl = urlService.getBaseUrl(location.href);
const jira = new JiraWrapper(baseUrl);

let generalSettings;

storage.getGeneralSettings()
.then((settings) => {
generalSettings = settings;

if (settings.optimisationsForNonJiraPages.enabled) {
return jira.checkIsInsideJira(baseUrl);
}
return Promise.resolve(true);
Promise.all([storage.getGeneralSettings(), checkIsInsideJira()])
.then((results) => {
const settings = results[0];
const insideJira = results[1];
this._initExtenders(insideJira, settings);
})
.then((insideJira) => this._initExtenders(insideJira, generalSettings))
.then(() => this.start());
}

start() {
this.extenders.forEach((extender) => {
extender.start();
});
this.extenders.forEach((extender) => extender.start());
}

_initExtenders(insideJira, settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ export default class GeneralSettings {
this.autoIssueSummary = {
enabled: true
};
this.optimisationsForNonJiraPages = {
enabled: true
};
}
}
3 changes: 2 additions & 1 deletion ReportJ.Extension.Chrome/app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"*://*/*"
],
"css": [
"build/content.css"
// todo: uncomment when styles would be added. MR
//"build/content.css"
],
"js": [
"build/manifest.js",
Expand Down
8 changes: 0 additions & 8 deletions ReportJ.Extension.Chrome/app/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ <h4>General</h4>
<input type="checkbox" ng-change="saveSettings()" ng-model="generalSettings.autoIssueSummary.enabled"> Automatically add issue summary to "Log Work" reports.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-change="saveSettings()" ng-model="generalSettings.optimisationsForNonJiraPages.enabled">
<span>Optimise performance for non-jira pages.</span>
<span class="glyphicon glyphicon-question-sign"
title="You may want to disable this option to avoid console error from ReportJ on non-jira pages (useful for devs). However disabling isn't recommended."></span>
</label>
</div>
</div>

<h4>Templates</h4>
Expand Down

0 comments on commit db09fc2

Please sign in to comment.