Skip to content

Commit

Permalink
Merge pull request #47 from leonhartX/support-ignore
Browse files Browse the repository at this point in the history
add ignore support
  • Loading branch information
leonhartX authored Nov 5, 2017
2 parents 5d5b3d7 + 80fe07c commit 8552afa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
6 changes: 3 additions & 3 deletions content/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
</div>
</div>
<div class="docs-toolbar-small-separator goog-toolbar-separator goog-inline-block">&nbsp;</div>
<div id="pullButton" class="goog-toolbar-menu-button goog-inline-block" title="Pull code from scm">
<div id="pull-button" class="goog-toolbar-menu-button goog-inline-block" title="Pull code from scm">
<div class="goog-toolbar-menu-button-outer-box goog-inline-block">
<div class="goog-toolbar-menu-button-inner-box goog-inline-block">Pull</div>
</div>
</div>
<div id="pushButton" class="goog-toolbar-menu-button goog-inline-block" title="Push code to scm">
<div id="push-button" class="goog-toolbar-menu-button goog-inline-block" title="Push code to scm">
<div class="goog-toolbar-menu-button-outer-box goog-inline-block">
<div class="goog-toolbar-menu-button-inner-box goog-inline-block">Push</div>
</div>
</div>
<div class="docs-toolbar-small-separator goog-toolbar-separator goog-inline-block">&nbsp;</div>
<div id="configButton" class="goog-toolbar-menu-button goog-inline-block" title="Config sync options">
<div id="config-button" class="goog-toolbar-menu-button goog-inline-block" title="Config sync options">
<div class="goog-toolbar-menu-button-outer-box goog-inline-block">
<div class="goog-toolbar-menu-button-inner-box goog-inline-block">Config</div>
</div>
Expand Down
24 changes: 15 additions & 9 deletions content/modal.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="diffModal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 180px; display: none;">
<div id="diff-modal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 180px; display: none;">
<div class="modal-dialog-title modal-dialog-title-draggable">
<span class="modal-dialog-title-text">Diff</span>
<span class="modal-dialog-title-text">(warning, only .gs and .html files will be synced)</span>
Expand All @@ -24,7 +24,7 @@
</div>
</div>

<div id="repoModal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div id="repo-modal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div class="modal-dialog-title modal-dialog-title-draggable">
<span class="modal-dialog-title-text">Create Repository</span>
<span class="scm-repo-modal-close modal-dialog-title-close"></span>
Expand All @@ -48,7 +48,7 @@
</tr>
<tr class="properties-data-dialog-table-row">
<td><div>Repository Name</div></td>
<td><input id="new-repo-name" class="editable-row-input large-input" type="text"></td>
<td><input id="new-repo-name" class="editable-row-input large-input" type="text" placeholder="new-repo-name"></td>
</tr>
<tr class="properties-data-dialog-table-row">
<td><div>Description</div></td>
Expand All @@ -74,7 +74,7 @@
</div>
</div>

<div id="gistModal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div id="gist-modal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div class="modal-dialog-title modal-dialog-title-draggable">
<span class="modal-dialog-title-text">Create Gist</span>
<span class="scm-gist-modal-close modal-dialog-title-close"></span>
Expand Down Expand Up @@ -113,7 +113,7 @@
</div>
</div>

<div id="branchModal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div id="branch-modal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div class="modal-dialog-title modal-dialog-title-draggable">
<span class="modal-dialog-title-text">Create Branch</span>
<span class="scm-branch-modal-close modal-dialog-title-close"></span>
Expand All @@ -130,7 +130,7 @@
</tr>
<tr class="properties-data-dialog-table-row">
<td><div>Branch Name</div></td>
<td><input id="new-branch-name" class="editable-row-input large-input" type="text"></td>
<td><input id="new-branch-name" class="editable-row-input large-input" type="text" placeholder="new-branch-name"></td>
</tr>
</tbody>
</table>
Expand All @@ -143,13 +143,13 @@
</div>
</div>

<div id="configModal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div id="config-modal" class="modal-dialog" tabindex="0" role="dialog" style="left: 274px; top: 280px; display: none;">
<div class="modal-dialog-title modal-dialog-title-draggable">
<span class="modal-dialog-title-text">Config sync options</span>
<span class="scm-config-modal-close modal-dialog-title-close"></span>
</div>
<div class="modal-dialog-content">
<div class="goog-inline-block" style="width: 400px; height: 90px;">
<div class="goog-inline-block" style="width: 600px; height: 100px;">
<div class="scm-config">
<table class="properties-data-dialog-table">
<tbody>
Expand All @@ -167,9 +167,15 @@
</select>
</div></td>
</tr>
</tbody>
<tr class="properties-data-dialog-table-row">
<td><div>Ignore filen patterns (regex separated by ';')</div></td>
<td><input id="ignore-pattern" class="editable-row-input large-input" type="text"></td>
</table>
</div>
</div>
</div>
<div class="scm-modal-button modal-dialog-buttons">
<button id="save-config" type="button" class="goog-buttonset-default goog-buttonset-action">Save</button>
<button type="button" class="scm-config-modal-close">Cancel</button>
</div>
</div>
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.1.0",
"version": "3.2.0",
"manifest_version": 2,
"default_locale": "en",
"name": "__MSG_appName__",
Expand Down
46 changes: 29 additions & 17 deletions src/gas-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ function initContext() {
context.id = match[2];

return new Promise((resolve, reject) => {
chrome.storage.sync.get(['scm', 'token', 'user', 'baseUrl', 'bindRepo', 'bindBranch', 'bindType'], (item) => {
chrome.storage.sync.get(['scm', 'token', 'user', 'baseUrl', 'bindRepo', 'bindBranch', 'bindType', 'bindPattern'], (item) => {
if (!item.token) {
reject(new Error('need login'));
}
if (!item.scm) {
reject(new Error('need relogin'));
}
scm = createSCM(item);
context.bindRepo = item.bindRepo || {};
context.bindBranch = item.bindBranch || {};
context.bindType = item.bindType || {};
context.bindPattern = item.bindPattern || {};
context.filetype = context.bindType[context.id] || '.gs';
context.ignorePattern = (context.bindPattern[context.id] || []).map(p => new RegExp(p));
context.gist = context.bindRepo[context.id] && context.bindRepo[context.id].gist;
resolve(scm);
});
Expand Down Expand Up @@ -188,31 +187,40 @@ function initPageEvent() {
});

['pull', 'push', 'config'].forEach((type) => {
$(document).on('mouseover', `#${type}Button`, () => {
$(`#${type}Button`).addClass('goog-toolbar-button-hover');
$(document).on('mouseover', `#${type}-button`, () => {
$(`#${type}-button`).addClass('goog-toolbar-button-hover');
});
$(document).on('mouseleave', `#${type}Button`, () => {
$(`#${type}Button`).removeClass('goog-toolbar-button-hover');
$(document).on('mouseleave', `#${type}-button`, () => {
$(`#${type}-button`).removeClass('goog-toolbar-button-hover');
});
});

['pull', 'push'].forEach(type => {
$(document).on('click', `#${type}Button`, () => {
$(document).on('click', `#${type}-button`, () => {
prepareCode()
.then((data) => { showDiff(data, type); }) //get more performance over callback
.catch((err) => { showAlert(err.message, LEVEL_ERROR); });
});
})

$(document).on('click', '#configButton', () => {
$(document).on('click', '#config-button', () => {
$('#filetype').val(context.filetype);
$('#ignore-pattern').val(context.bindPattern[context.id].join(';'));
changeModalState('config', true);
});

$(document).on('change', '#filetype', () => {
$(document).on('click', '#save-config', () => {
context.filetype = $('#filetype').val();
context.bindType[context.id] = context.filetype;
chrome.storage.sync.set({ bindType: context.bindType });
let pattern = $('#ignore-pattern').val().split(';').filter(p => p !== '');
context.bindPattern[context.id] = pattern;
try {
context.ignorePattern = pattern.map(p => new RegExp(p));
chrome.storage.sync.set({ bindType: context.bindType, bindPattern: context.bindPattern });
changeModalState('config', false);
} catch (err) {
showAlert(err.message, LEVEL_ERROR);
}
})

$(document).on('click', '.scm-item', (event) => {
Expand Down Expand Up @@ -303,7 +311,11 @@ function showDiff(code, type) {
return gasFiles.indexOf(e) < 0;
})
.concat(gasFiles)
.filter((file) => {
.filter(file => {
for (let i = 0; i < context.ignorePattern.length; i ++) {
let p = context.ignorePattern[i];
if (p.test(file)) return false;
}
const match = file.match(/(.*?)\.(gs|html)$/);
return match && match[1] && match[2];
})
Expand Down Expand Up @@ -491,14 +503,14 @@ function getBaseUrl() {

function changeModalState(type, toShow) {
if (toShow) {
const margin = type === 'config' ? 600 : 400;
const margin = 600;
const width = $('body').width();
const height = $('body').height();
const left = (width - margin) / 2;
$(`#${type}Modal`).before(`<div class="scm-modal-bg modal-dialog-bg" style="opacity: 0.5; width: ${width}px; height: ${height}px;" aria-hidden="true"></div>`);
$(`#${type}Modal`).css('left', left).show();
$(`#${type}-modal`).before(`<div class="scm-modal-bg modal-dialog-bg" style="opacity: 0.5; width: ${width}px; height: ${height}px;" aria-hidden="true"></div>`);
$(`#${type}-modal`).css('left', left).show();
} else {
$(`#${type}Modal`).hide();
$(`#${type}-modal`).hide();
$('.scm-modal-bg').remove();
$(`#new-${type}-name`).css('border-color', '');
}
Expand Down

0 comments on commit 8552afa

Please sign in to comment.