Skip to content

Commit

Permalink
Merge pull request #42 from barriosnahuel/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
barriosnahuel committed Feb 29, 2016
2 parents 2338871 + 4b4726c commit df76ca4
Show file tree
Hide file tree
Showing 94 changed files with 248 additions and 88 deletions.
30 changes: 9 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ It's a GitHub's notifications interpreter for Chrome
[![Code Climate](https://codeclimate.com/github/barriosnahuel/spokesman/badges/gpa.svg)](https://codeclimate.com/github/barriosnahuel/spokesman)
[![Issue Count](https://codeclimate.com/github/barriosnahuel/spokesman/badges/issue_count.svg)](https://codeclimate.com/github/barriosnahuel/spokesman)

## Project status

[![Throughput Graph](https://graphs.waffle.io/barriosnahuel/spokesman/throughput.svg)](https://waffle.io/barriosnahuel/spokesman/metrics)

Working on: [![Issues ready to take](https://badge.waffle.io/barriosnahuel/spokesman.png?label=ready&title=Ready)](https://waffle.io/barriosnahuel/spokesman)

## Screenshots

See [listing](https://goo.gl/vBtHnG) in Chrome's store.
Expand Down Expand Up @@ -48,34 +54,16 @@ is not present, then it fails and log:

1. Clone this repo in your favourite directory.
2. Open Chrome and go to `chrome://extensions`
3. Assure **Developer mode** isAdded checked, if not then check it.
4. Click on **Load unpacked extension**, then select the root directory of the cloned repository.
3. Assure **Developer mode** is checked, if not then check it.
4. Click on **Load unpacked extension**, then select the `extension` directory of the cloned repository.
5. Setup your username and personal access token on the settings page.

**Important:** Take into account that for private repos your access token *must* have the `repo` permission enabled.
**Important:** Take into account that for private repositories your access token *must* have the `repo` permission enabled.

### Configure properties file
Edit `properties.json` file in the root directory (just next to this file) and add
- `"testing": true` <= It's an important flag to prevent checking for new events once a minute.

Sample file:

```json
{
"testing": true,
"push_branches": [
"master",
"develop",
"development"
],
"issues_action": [
"opened",
"closed",
"reopened"
]
}
```

### icons

Icons were taken from [here](http://www.iconsdb.com/black-icons/megaphone-2-icon.html) and [here](http://www.flaticon.com/free-icon/leader-with-loudspeaker_75899#term=megaphone&page=1&position=12).
Expand Down
6 changes: 0 additions & 6 deletions css/bootstrap.min.css

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions extension/css/bootstrap.min.css

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions css/settings.css → extension/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ form div.input-group {
margin-top: 20px;
}

.glyphicon.glyphicon-remove:hover {
cursor: pointer;
}

.spk-inner-addon > .glyphicon {
z-index: 2;
}
Expand Down Expand Up @@ -66,4 +70,12 @@ form div.input-group .form-control:not(:first-child):not(:last-child) {

#issues > li > ul > li {
min-width: 160px;
}

.spk-supported-event {
height: 34px;
}

.spk-supported-event > div:first-child {
margin-top: 7px;
}
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
75 changes: 57 additions & 18 deletions js/bend/background.js → extension/js/bend/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ var spk = spk || {};
var isProcessingQueue;

var onExtensionInstalledOrUpdated = function (details) {
var openSettingsPage = function (showChangelog) {
chrome.tabs.create({
url: 'views/settings.html' + (showChangelog ? '#changelog' : '')
}, undefined);
};

console.info('Running onInstalled, reason: %s', details.reason);
console.info('Previous version: %s', details.previousVersion);

if (details.reason === 'install') {
chrome.tabs.create({
url: 'views/settings.html'
}, undefined);
openSettingsPage();
} else if (details.reason === 'update' && details.previousVersion === '1.0.1') {
openSettingsPage(true);
}
};

Expand All @@ -36,7 +42,6 @@ var spk = spk || {};

var saveQueue = function (queue) {
chrome.storage.local.set({'queue': queue}, undefined);
console.debug('Saved queue w/ size: %d', queue.length);
};

var scheduleNotifications = function (notifications) {
Expand Down Expand Up @@ -108,8 +113,6 @@ var spk = spk || {};
};

var runAPICall = function () {
console.debug('==> runAPICall...');

console.info('Checking for new notifications...');

spk.lib.getEvents(function (err, events) {
Expand All @@ -122,10 +125,7 @@ var spk = spk || {};
for (var i = events.length - 1; i >= 0; i -= decrement, decrement = 1, mergedEventsQuantity = undefined) {
var currentEvent = events[i];

if (lastEventId && currentEvent.id <= lastEventId) {
console.debug('Skipping event %s because last read event is %s.', currentEvent.id, lastEventId);
} else {

if (!lastEventId || currentEvent.id > lastEventId) {
if (!mergedEventsQuantity) {
mergedEventsQuantity = spk.events.custom.issuesEvents.check(events, i, currentEvent);
}
Expand All @@ -145,6 +145,43 @@ var spk = spk || {};
return mergedEvents;
};

/**
* This method is duplicated in settings.js
* @param supportedEvents
* @param event
* @returns {*}
*/
function findEvent(supportedEvents, event) {
var result;
for (var j = 0; j < supportedEvents.length; j++) {
var eachSupportedEventType = supportedEvents[j];
if (eachSupportedEventType.event === event) {
result = eachSupportedEventType;
break;
}
}
return result;
}

/**
* Filter events with a type that there is NOT in the enabledEventTypes array.
* @param enabledEventTypes Event types that are currently enabled in the settings page.
* @param events Events from GitHub API response.
* @returns {Array} an array of events that the user has set as enabled.
*/
var getEnabledEvents = function (enabledEventTypes, events) {
var filteredEvents = [];
for (var i = 0; i < events.length; i++) {
var eachEvent = events[i];
var eventType = findEvent(enabledEventTypes, eachEvent.type);
if (eventType && eventType.enabled) {
filteredEvents.push(eachEvent);
}
}

return filteredEvents;
};

if (err) {
console.error('Can\'t get GitHub\'s events: %s', err);
} else {
Expand All @@ -158,7 +195,15 @@ var spk = spk || {};
spk.properties.issues_action = storage.issues;
}

var mergedEvents = mergeEvents(storage.lastEventId, events);
if (storage.supportedEvents) {
spk.properties.supported_events = storage.supportedEvents;
} else {
chrome.storage.sync.set({'supportedEvents': spk.properties.supported_events}, undefined);
}

var enabledEvents = getEnabledEvents(spk.properties.supported_events, events);

var mergedEvents = mergeEvents(storage.lastEventId, enabledEvents);

var notifications = [];
for (var i = 0; i < mergedEvents.length; i++) {
Expand All @@ -170,7 +215,6 @@ var spk = spk || {};
}
}

console.debug('Created %d/%d notifications based on API response.', notifications.length, events.length);
scheduleNotifications(notifications);

console.info('Last event/notification read %s', events[0].id);
Expand All @@ -181,12 +225,7 @@ var spk = spk || {};
};

var processQueue = function () {
console.debug('==> processQueue...');

if (isProcessingQueue) {
console.debug('Queue is already being processed.')
} else {
console.debug('Start queue process because of a new alarm.');
if (!isProcessingQueue) {
dequeue();
}
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
112 changes: 94 additions & 18 deletions js/fend/settings.js → extension/js/fend/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var spk = spk || {};
$(document).ready(function () {

$.templates("branchInput", "#branchInputTemplate");
$.templates("supportedEvent", "#supportedEventTemplate");

var $username = $('#username');
var $accessToken = $('#accessToken');
Expand All @@ -15,6 +16,12 @@ $(document).ready(function () {
var $branchesList = $('#branches');
var branches;
var issues;
var supportedEvents;

var showChangelog = (function (url) {
var changelogSuffix = '#changelog';
return url.indexOf(changelogSuffix, url.length - changelogSuffix.length) !== -1;
}(window.location.href));

render();
addListeners();
Expand All @@ -37,29 +44,49 @@ $(document).ready(function () {
chrome.storage.sync.get(undefined, function (storage) {
branches = storage.branches || [];
issues = storage.issues || [];
supportedEvents = storage.supportedEvents;

$.ajax({
url: '../properties.json',
dataType: 'json',
async: false
}).done(function (properties) {
if (!storage.branches) {
branches = properties.push_branches;
saveBranches();
}

if (!storage.branches || !storage.issues) {
$.ajax({
url: '../properties.json',
dataType: 'json',
async: false
}).done(function (properties) {
if (!storage.branches) {
branches = properties.push_branches;
saveBranches();
}
if (!storage.issues) {
issues = properties.issues_action;
saveIssues();
}

if (!storage.issues) {
issues = properties.issues_action;
saveIssues();
}
if (!supportedEvents) {
supportedEvents = properties.supported_events;
saveEnabledEvents();
}

addBranches();
addIssuesActions();
});
} else {
addBranches();
addIssuesActions();
addSupportedEvents();
});

if (showChangelog) {
var $changelog = $('.spk-supported-event:first>.pull-right');
$changelog.popover({
title: 'NEW in v1.1.0'
, content: 'From now on you can disable each event type if you don\'t want to keep receiving notifications.'
, placement: 'top'
, trigger: 'hover'
, delay: {
"show": 0
, "hide": 1000
}
}).on('hidden.bs.popover', function () {
$changelog.popover('destroy');
}).popover('show');

$('html,body').animate({scrollTop: $('div.popover').offset().top});
}

function addBranches() {
Expand Down Expand Up @@ -96,6 +123,47 @@ $(document).ready(function () {
});
}
}

/**
* This method is duplicated in background.js
* @param supportedEvents
* @param event
* @returns {*}
*/
function findEvent(supportedEvents, event) {
var result;
for (var j = 0; j < supportedEvents.length; j++) {
var eachSupportedEventType = supportedEvents[j];
if (eachSupportedEventType.event === event) {
result = eachSupportedEventType;
break;
}
}
return result;
}

function addSupportedEvents() {
var $list = $('#supportedEvents');

for (var i = 0; i < supportedEvents.length; i++) {
var eachEvent = supportedEvents[i];

$list.append($.render.supportedEvent(eachEvent));

var $checkbox = $list.find('input:last-child');
$checkbox.bootstrapToggle();
$checkbox.change(function () {
var $this = $(this);

var eventType = findEvent(supportedEvents, $this.val());
eventType.enabled = $this.prop('checked');

saveEnabledEvents();

console.dir(supportedEvents);
});
}
}
});
}

Expand Down Expand Up @@ -197,4 +265,12 @@ $(document).ready(function () {
}
});
};

var saveEnabledEvents = function (callback) {
chrome.storage.sync.set({'supportedEvents': supportedEvents}, function () {
if (callback) {
callback();
}
});
};
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion manifest.json → extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Spokesman - GitHub's notifications",
"short_name": "Spokesman",
"version": "1.0.1",
"version": "1.1.0",
"description": "Get desktop notifications of events that occur on GitHub that really interest you.",
"browser_action": {
"default_icon": {
Expand Down
Loading

0 comments on commit df76ca4

Please sign in to comment.