UNPKG

@jupyterlab/git

Version:

A JupyterLab extension for version control using git

82 lines (81 loc) 3.58 kB
import { Widget } from '@lumino/widgets'; /** * A widget form with advanced push options, * can be used as a Dialog body. */ export class AdvancedPushForm extends Widget { constructor(trans, model) { super(); this._trans = trans; this._model = model; this._radioButtons = []; this.node.appendChild(this.createBody()); this.addRemoteOptions(); } createBody() { const mainNode = document.createElement('div'); // Instructional text const text = document.createElement('div'); text.className = 'jp-remote-text'; text.textContent = this._trans.__('Choose a remote to push to.'); // List of remotes const remoteOptionsContainer = document.createElement('div'); remoteOptionsContainer.className = 'jp-remote-options-wrapper'; const loadingMessage = document.createElement('div'); loadingMessage.textContent = this._trans.__('Loading remote repositories...'); remoteOptionsContainer.appendChild(loadingMessage); this._remoteOptionsContainer = remoteOptionsContainer; // Force option const forceCheckboxContainer = document.createElement('label'); forceCheckboxContainer.className = 'jp-force-box-container'; this._forceCheckbox = document.createElement('input'); this._forceCheckbox.type = 'checkbox'; this._forceCheckbox.checked = false; const label = document.createElement('span'); label.textContent = this._trans.__('Force Push'); forceCheckboxContainer.appendChild(this._forceCheckbox); forceCheckboxContainer.appendChild(label); mainNode.appendChild(text); mainNode.appendChild(remoteOptionsContainer); mainNode.appendChild(forceCheckboxContainer); return mainNode; } async addRemoteOptions() { const remotes = await this._model.getRemotes(); this._remoteOptionsContainer.innerHTML = ''; if (remotes.length > 0) { remotes.forEach(remote => { const buttonWrapper = document.createElement('div'); buttonWrapper.className = 'jp-button-wrapper'; const radioButton = document.createElement('input'); radioButton.type = 'radio'; radioButton.id = remote.name; radioButton.value = remote.name; radioButton.name = 'option'; radioButton.className = 'jp-option'; if (remote.name === 'origin') { radioButton.checked = true; } this._radioButtons.push(radioButton); const label = document.createElement('label'); label.htmlFor = remote.name; label.textContent = `${remote.name}: ${remote.url}`; buttonWrapper.appendChild(radioButton); buttonWrapper.appendChild(label); this._remoteOptionsContainer.appendChild(buttonWrapper); }); } else { const noRemoteMsg = document.createElement('div'); noRemoteMsg.textContent = this._trans.__('This repository has no known remotes.'); this._remoteOptionsContainer.appendChild(noRemoteMsg); } } getValue() { var _a, _b; return { remoteName: (_b = (_a = this._radioButtons.find(rb => rb.checked)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '', force: this._forceCheckbox.checked }; } }