Skip to content

Commit ec41478

Browse files
committed
Add bb issue context & popup option
1 parent 76b449a commit ec41478

File tree

9 files changed

+64
-24
lines changed

9 files changed

+64
-24
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "Gitpod - Dev Environments in a Browser Tab",
44
"short_name": "Gitpod",
5-
"version": "1.5",
5+
"version": "1.6",
66
"description": "Describe your dev environment as code and get fully prebuilt dev environments for any GitLab, GitHub and Bitbucket project.",
77
"icons": {
88
"16": "icons/gitpod-logo-16.png",

src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { EventEmitter } from "events";
33

44
export interface Config {
55
gitpodURL: string;
6+
openAsPopup: boolean;
67
}
78

89
export const DEFAULT_CONFIG: Config = {
9-
gitpodURL: "https://gitpod.io"
10+
gitpodURL: "https://gitpod.io",
11+
openAsPopup: false
1012
};
1113

1214
export interface ConfigListener {

src/injectors/bitbucket-injector.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { InjectorBase, ButtonInjector, checkIsBtnUpToDate } from "./injector";
22
import { ConfigProvider } from "../config";
3-
import { renderGitpodUrl } from "../utils";
3+
import { renderGitpodUrl, makeOpenInPopup } from "../utils";
44
import select = require("select-dom");
55

66
namespace Gitpodify {
@@ -18,6 +18,7 @@ export class BitbucketInjector extends InjectorBase {
1818
super(configProvider, [
1919
new BranchInjector(),
2020
new PullRequestInjector(),
21+
new IssuesInjector(),
2122
new NewPullRequestInjector(),
2223
new CommitInjector(),
2324
new RepositoryInjector()
@@ -59,7 +60,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {
5960

6061
abstract isApplicableToCurrentPage(): boolean;
6162

62-
inject(currentUrl: string) {
63+
inject(currentUrl: string, openAsPopup: boolean) {
6364
let actionbar = select(this.parent);
6465
if(actionbar && this.up) {
6566
for(let i = 0; i < this.up; i++) {
@@ -84,19 +85,19 @@ abstract class ButtonInjectorBase implements ButtonInjector {
8485
return;
8586
}
8687

87-
const btn = this.renderButton(currentUrl);
88+
const btn = this.renderButton(currentUrl, openAsPopup);
8889

8990
const btnGroup = actionbar.children;
9091
if (btnGroup && btnGroup.length > 0){
9192
actionbar.insertBefore(btn, btnGroup[0]);
9293
}
9394
}
9495

95-
protected renderButton(url: string, float: boolean = true): HTMLElement {
96+
protected renderButton(url: string, openAsPopup: boolean, float: boolean = true): HTMLElement {
9697
let classes = Gitpodify.NAV_BTN_CLASS;
9798
if (float) {
9899
classes = `${classes} ${this.btnClasses} aui-button`;
99-
}
100+
}
100101

101102
const container = document.createElement('div');
102103
container.id = Gitpodify.CSS_REF_BTN_CONTAINER;
@@ -108,6 +109,9 @@ abstract class ButtonInjectorBase implements ButtonInjector {
108109
a.text = "Gitpod"
109110
a.href = url;
110111
a.target = "_blank";
112+
if (openAsPopup) {
113+
makeOpenInPopup(a);
114+
}
111115
a.className = "btn btn-sm btn-primary";
112116

113117
container.appendChild(a);
@@ -151,6 +155,18 @@ class NewPullRequestInjector extends ButtonInjectorBase {
151155

152156
}
153157

158+
class IssuesInjector extends ButtonInjectorBase {
159+
160+
constructor() {
161+
super('#issue-header .aui-buttons:last-child', '');
162+
}
163+
164+
isApplicableToCurrentPage(): boolean {
165+
return select(this.parent) && window.location.pathname.includes("/issues/");
166+
}
167+
168+
}
169+
154170
class CommitInjector extends ButtonInjectorBase {
155171

156172
constructor() {

src/injectors/github-injector.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as select from 'select-dom';
22
import * as ghInjection from 'github-injection';
33
import { ConfigProvider } from '../config';
44
import { ButtonInjector, InjectorBase, checkIsBtnUpToDate } from './injector';
5-
import { renderGitpodUrl } from '../utils';
5+
import { renderGitpodUrl, makeOpenInPopup } from '../utils';
66

77
namespace Gitpodify {
88
export const NAV_BTN_ID = "gitpod-btn-nav";
@@ -71,7 +71,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {
7171

7272
abstract isApplicableToCurrentPage(): boolean;
7373

74-
inject(currentUrl: string) {
74+
inject(currentUrl: string, openAsPopup: boolean) {
7575
const actionbar = select(this.parentSelector);
7676
if (!actionbar) {
7777
return;
@@ -87,7 +87,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {
8787
return;
8888
}
8989

90-
const btn = this.renderButton(currentUrl);
90+
const btn = this.renderButton(currentUrl, openAsPopup);
9191

9292
const btnGroup = actionbar.getElementsByClassName("BtnGroup");
9393
if (btnGroup && btnGroup.length > 0 && btnGroup[0].classList.contains('float-right')){
@@ -99,7 +99,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {
9999
}
100100
}
101101

102-
protected renderButton(url: string): HTMLElement {
102+
protected renderButton(url: string, openAsPopup: boolean): HTMLElement {
103103
let classes = this.btnClasses + ` ${Gitpodify.NAV_BTN_CLASS}`;
104104
if (this.float) {
105105
classes = classes + ` float-right`;
@@ -115,6 +115,9 @@ abstract class ButtonInjectorBase implements ButtonInjector {
115115
a.text = "Gitpod"
116116
a.href = url;
117117
a.target = "_blank";
118+
if (openAsPopup) {
119+
makeOpenInPopup(a);
120+
}
118121
a.className = "btn btn-sm btn-primary";
119122

120123
this.adjustButton(a);

src/injectors/gitlab-injector.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as domloaded from 'dom-loaded';
22
import * as select from 'select-dom';
33
import { ConfigProvider } from '../config';
44
import { ButtonInjector, InjectorBase, checkIsBtnUpToDate } from './injector';
5-
import { renderGitpodUrl } from '../utils';
5+
import { renderGitpodUrl, makeOpenInPopup } from '../utils';
66

77
namespace Gitpodify {
88
export const BTN_ID = "gitpod-btn-nav";
@@ -54,7 +54,7 @@ class RepositoryInjector implements ButtonInjector {
5454
return result;
5555
}
5656

57-
inject(currentUrl: string) {
57+
inject(currentUrl: string, openAsPopup: boolean) {
5858
const parent = select(RepositoryInjector.PARENT_SELECTOR);
5959
if (!parent || !parent.firstElementChild) {
6060
return;
@@ -67,12 +67,11 @@ class RepositoryInjector implements ButtonInjector {
6767
return;
6868
}
6969

70-
const btn = this.renderButton(currentUrl);
71-
console.log(parent.innerHTML);
70+
const btn = this.renderButton(currentUrl, openAsPopup);
7271
parent.firstElementChild.appendChild(btn);
7372
}
7473

75-
protected renderButton(url: string): HTMLElement {
74+
protected renderButton(url: string, openAsPopup: boolean): HTMLElement {
7675
const container = document.createElement('div');
7776
container.className = "project-clone-holder d-none d-md-inline-block";
7877

@@ -86,6 +85,10 @@ class RepositoryInjector implements ButtonInjector {
8685
a.href = url;
8786
a.target = "_blank";
8887
a.className = "btn btn-primary";
88+
89+
if (openAsPopup) {
90+
makeOpenInPopup(a);
91+
}
8992

9093
container2ndLevel.appendChild(a);
9194
container.appendChild(container2ndLevel);

src/injectors/injector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface ButtonInjector {
3636
* Injects the actual button
3737
* @param currentUrl The currently configured Gitpod URL
3838
*/
39-
inject(currentUrl: string): void;
39+
inject(currentUrl: string, openAsPopup: boolean): void;
4040
}
4141

4242
export abstract class InjectorBase implements Injector {
@@ -54,7 +54,7 @@ export abstract class InjectorBase implements Injector {
5454
const currentUrl = renderGitpodUrl(this.config.gitpodURL);
5555
for (const injector of this.buttonInjectors) {
5656
if (injector.isApplicableToCurrentPage()) {
57-
injector.inject(currentUrl);
57+
injector.inject(currentUrl, this.config.openAsPopup);
5858
if (singleInjector) {
5959
break;
6060
}

src/options/options.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<label>Gitpod installation URL:</label>
1111
<input id="gitpod-url-input" type="url" value=""/>
1212
</div>
13+
<div class="row">
14+
<label>Open as popup:</label>
15+
<input id="gitpod-open-as-popup" type="checkbox"/>
16+
</div>
1317
<div class="row">
1418
<div style="min-width: 5em;"></div>
1519
<div><a href="https://www.gitpod.io/docs/browser-extension/">https://www.gitpod.io/docs/browser-extension/</a></div>

src/options/options.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ConfigProvider } from "../config";
22

33
const gitpodUrlInput = document.getElementById("gitpod-url-input")! as HTMLInputElement;
4+
const gitpodPopupInput = document.getElementById("gitpod-open-as-popup")! as HTMLInputElement;
45
const messageElement = document.getElementById("message")! as HTMLDivElement;
56

67

@@ -10,18 +11,16 @@ const init = async () => {
1011
// Initialize UI
1112
const initialConfig = configProvider.getConfig();
1213
gitpodUrlInput.value = initialConfig.gitpodURL;
14+
gitpodPopupInput.checked = initialConfig.openAsPopup;
1315

1416
let timeout: number | undefined = undefined;
1517

1618
// Save config before close
17-
const saveOnType = (event: KeyboardEvent) => {
18-
if (event.isComposing || event.keyCode === 229) {
19-
return;
20-
}
21-
19+
const save = () => {
2220
// Update config (propagated internally)
2321
configProvider.setConfig({
2422
gitpodURL: gitpodUrlInput.value || undefined,
23+
openAsPopup: gitpodPopupInput.checked
2524
});
2625
if (timeout) {
2726
window.clearTimeout(timeout);
@@ -30,7 +29,13 @@ const init = async () => {
3029
messageElement.innerText = "Saved.";
3130
timeout = window.setTimeout(() => { messageElement.innerText = ""; timeout = undefined }, 3000);
3231
};
33-
gitpodUrlInput.addEventListener("keyup", saveOnType);
32+
gitpodUrlInput.addEventListener("keyup", (event: KeyboardEvent) => {
33+
if (event.isComposing || event.keyCode === 229) {
34+
return;
35+
}
36+
save()
37+
});
38+
gitpodPopupInput.addEventListener('change', save);
3439
};
3540

3641
init().catch(err => console.error(err));

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ export function renderGitpodUrl(gitpodURL: string): string {
22
const baseURL = `${window.location.protocol}//${window.location.host}`;
33
return `${gitpodURL}/#${baseURL}` + window.location.pathname;
44
}
5+
6+
export function makeOpenInPopup(a: HTMLAnchorElement): void {
7+
a.onclick = () => {
8+
var w = window.open(a.href, a.target, 'menubar=no,toolbar=no,location=no,dependent');
9+
return !w;
10+
}
11+
}

0 commit comments

Comments
 (0)