Skip to content

Commit

Permalink
Merge pull request #4 from esphen/next
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
Espen H committed Oct 10, 2015
2 parents e4a0e96 + d22fd25 commit afe872b
Show file tree
Hide file tree
Showing 51 changed files with 1,075 additions and 174 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.xpi
install.rdf
node_modules
bootstrap.js
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.1.2
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "4.1"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ A REST client for the rest of us.

_Note: This is the source code, the extension download is [here](https://addons.mozilla.org/en-US/firefox/addon/rested/?src=search)._

[![Build Status](https://travis-ci.org/esphen/RESTED.svg?branch=master)](https://travis-ci.org/esphen/RESTED)

RESTED is a new take on rest clients on Firefox.
It is designed to be easy to use to let you work as effective as possible.
It features all the most commonly used HTTP methods, setting headers,
saving requests to local storage, and more.
It features all the most commonly used HTTP methods, setting headers, beautiful themes,
saving requests in your browser, and more.

Since this is a relatively new project, I am also happy to announce that
it is also awesomely easy to contribute to the project! Everything is
Expand All @@ -20,17 +22,10 @@ that they will be merged - requests will be reviewed).
This project was from the very beginning intended to be easy to work with.
It is basically just an angular 1.4 app inside of Firefox, so if you know angular, you're in luck!

Features in 0.3, currently in review:
- Remove headers from request
- Spinner for slow requests
- Changes undelying implementation $http -> XHR
- Https urls should no longer break
- Responsive adjustments - should now look good on monitors for mice

What features are on the to-do list:
- Improve collections with collapsible collection groups
- Request history
- Export and import collections from file
- Export collections
- Improve pretty-printing of results

In order to work on this project, you're going to need a few things:
Expand All @@ -44,7 +39,7 @@ If you use the Extension Auto-Installer, clone this project and run `jpm watchpo
The extension will then be reinstalled every time you save a file, without you having to do a thing.

If you don't use Extension Auto-Installer, you need to do what the extension does for you manually every time you save.
That is, `jpm xpi && firefox rested@restedclient-0.1.2.xpi`.
That is, `jpm xpi && firefox rested@restedclient-0.x.y.xpi` (remember to change the version number).

Note: Soon Mozilla will require unsigned extenstions (not from addons.mozilla.org) to be run in [Nightly](https://www.mozilla.org/firefox/nightly/).
If you see a "RESTED could not be verified for use in Firefox", you may need to go get Nightly and develop from there. You also need to go to
Expand All @@ -55,7 +50,28 @@ a chrome URL. Try starting up a [static webserver](https://www.npmjs.com/package
dev tools should work as normal. Note that you cannot run requests from the static web server, as one does not have the elevated
permissions the chrome URLs get.

Another indexedDB tip: If you need to empty and reset the database, enter `indexedDB.deleteDatabase('RESTED');` into your developer console.
That should clear the entire database and force a clean install on refresh.

**Please develop on the next branch.**
This makes it easier for me to merge and prepare releases in the future.
Thanks for the interest!

### Tests
This project runs unit tests through travis-ci. This is to ensure critical components correctness, there is no 100% test coverage requirement.
If you make an addition, please consider if your change is critical in nature, i.e. would cause grief if stops working or is not correct.
If this is the case, please write unit tests for your feature.

In order to run the test suite on your machine, the following is required:
- [nodejs](https://nodejs.org/en/)
- [npm](https://www.npmjs.com/)
- [nvm](https://github.com/creationix/nvm)

After installing the required components, navigate to the root folder of the project and set up the test suite:
```
$ nvm use
$ npm install
```

Now you can `npm test` for a single-run test, or `npm run dev` for continually watching files and running tests on change.

21 changes: 20 additions & 1 deletion data/css/spesific.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ body {
margin-top: -7px;
}

/* TODO: Figure out logo on black themes */
.header>h1 {
color: #222222;
}

#headerSlider {
margin-top: 30px;
}
Expand Down Expand Up @@ -77,6 +82,20 @@ slidey-button {
/* Makes the animation look a bit more sane */
white-space: nowrap;
}
.remove-header {
.remove-header,
.remove-url-parameter {
margin-top: 10px;
}

.list-group-item-text {
word-break: break-all;
}

.import-type-buttons {
margin-top: 15px;
}

.import-textarea {
margin-top: 15px;
resize: vertical;
}
5 changes: 5 additions & 0 deletions data/ext/bootstrap.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/cerulean.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/cosmo.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/cyborg.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/darkly.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/flatly.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/journal.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/lumen.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/paper.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/readable.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/sandstone.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/simplex.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/slate.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/spacelab.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/superhero.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/united.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions data/ext/bootswatch/yeti.min.css

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion data/js/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var module = angular.module('RestedApp');
// there will be an onupgradeneeded event called
// which we can use to convert users on older
// paradigms to the current one.
module.constant('DB_VERSION', 3);
module.constant('DB_VERSION', 4);

// The name of our entire indexedDB instance.
module.constant('DB_NAME', 'RESTED');
Expand All @@ -21,6 +21,10 @@ module.constant('DB_OBJECT_STORE_NAME', 'collections');
// our URL variables.
module.constant('DB_URL_VARIABLES_STORE_NAME', 'urlVariables');

// The name of the "table" in indexedDB we use for
// storing application options
module.constant('DB_OPTIONS_STORE_NAME', 'options');

// This is the request used to initialize the
// request panel. This can be either on
// application load or on request reset.
Expand All @@ -37,6 +41,34 @@ module.constant('DEFAULT_REQUEST', {
// after a request has been sent.
module.constant('SPINNER_SHOW_DELAY', 300);

// These are the themes available on bootswatch,
// alphabethic order - except application default
// (yeti) first, then bootstrap default (retro).
//
// TODO: There are some themes (Black backgrounds)
// that simply DO NOT work with the logo. We need
// to figure out something if we want to add them
// back in. (Make logo white?)
module.constant('THEMES', [
'yeti',
'retro',
'cerulean',
'cosmo',
//'cyborg',
//'darkly',
'flatly',
'journal',
'lumen',
'paper',
'readable',
'sandstone',
'simplex',
//'slate',
'spacelab',
'superhero',
'united'
]);

// The URLs shown in the URL bar on load.
// Add more if you want!
// The only rule for these: Nothing NSFW or illegal
Expand All @@ -53,6 +85,7 @@ module.constant('PLACEHOLDER_URLS', [
'http://www.aperturescience.com',
'http://www.pennyjuice.com/htmlversion/whoispj.htm',
'http://www.arngren.net/',
'http://www.lingscars.com/',
'http://bojackhorseman.com',
'http://visitnorway.com',
]);
Expand Down
65 changes: 65 additions & 0 deletions data/js/controllers/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';

angular.module('RestedApp')
.controller('OptionsCtl', function($scope, $rootScope, Import, Modal, Collection, UrlVariables) {
$scope.activeTab = 'templateVariablesForm';
$scope.importMethod = 'HAR';

var doImport = function() {
var requests;

try {
var importObj = JSON.parse($scope.importText);
requests = Import['from' + $scope.importMethod](importObj);
} catch(e) {
console.error(e);
return $scope.importFeedback = 'Error while parsing. Is your text formatted correctly?';
}

Modal.set({
title: 'Successfy parsed imports',
body: 'Would you like to add the following to your collection or replace your existing collection?',
actions: [{
text: 'Add',
click: function() {
requests.forEach(function(request) {
Collection.addRequestToCollection(request);
Modal.remove();
});
}
}, {
text: 'Replace',
click: function() {
Collection.clearCollection(function callback() {
requests.forEach(Collection.addRequestToCollection);
});
}
}]
});
};

var actions = {
templateVariablesForm: [{
text: 'Save',
click: UrlVariables.setVariables
}],
optionsForm: [{
text: 'Save'
}],
importForm: [{
text: 'Import',
click: doImport
}]
};

$scope.setTab = function(tabName) {
$scope.activeTab = tabName;
$rootScope.modalOptions.actions = actions[tabName];
};

$scope.removeParam = function(param) {
$rootScope.urlVariables = $rootScope.urlVariables.filter(function(item) {
return item !== param;
});
};
});
78 changes: 23 additions & 55 deletions data/js/controllers/root.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
'use strict';

angular.module('RestedApp')
.controller('RootCtl', function(DEFAULT_REQUEST, $rootScope, DB, Modal) {
.controller('RootCtl', function(DEFAULT_REQUEST, THEMES, $rootScope, DB, Collection, Modal) {

$rootScope.request = angular.copy(DEFAULT_REQUEST);
$rootScope.themes = THEMES;
$rootScope.collections = [];
$rootScope.urlVariables = [];

var errorHandler = function(event) {
console.error(event);
Modal.set({
title: 'An error occured',
body: event.message
});
};

var errorHandler = Modal.errorHandler;
// Data is saved in the db like so:
// [
// {
Expand Down Expand Up @@ -57,57 +51,26 @@ angular.module('RestedApp')
$rootScope.urlVariables = data && data[0] && data[0].variables ? data[0].variables : [];
}, errorHandler);

// Data is saved in db like so:
// [
// {
// name: 'options',
// options: {
// key: 'value'
// }
// }
// ]
DB.options.get().then(function(data) {
$rootScope.options = data && data[0] && data[0].options ? data[0].options : {};
}, errorHandler);

// Called on request addition
// This is exposed to lower scopes
$rootScope.addRequestToCollection = function(request) {

// Create new collection if none exist
if (!$rootScope.collections[0]) {
$rootScope.collections.push({
name: 'Collection',
requests: [request]
});

DB.collections.add($rootScope.collections[0]).then(null, errorHandler);
} else if ($rootScope.collections[0].requests.indexOf(request) === -1) {
$rootScope.collections[0].requests.push(request);

DB.collections.set($rootScope.collections[0]).then(null, errorHandler);
} else {
Modal.set({
title: 'Hey!',
body: 'Request is already in collection. Overwrite existing entry?',
action: {
text: 'OK',
click: function() {
DB.collections.set($rootScope.collections[0]).then(null, errorHandler);
Modal.remove();
}
}
});
}
};
$rootScope.addRequestToCollection = Collection.addRequestToCollection;

// Called on request removal
// This is exposed to lower scopes
$rootScope.removeRequestFromCollection = function(request) {
Modal.set({
title: 'Confirm deletion',
body: 'Please confirm you wish to remove this request from your saved collection',
action: {
text: 'Confirm',
click: function() {
$rootScope.collections[0].requests = $rootScope.collections[0].requests.filter(function(item) {
return item.url !== request.url;
});

DB.collections.set($rootScope.collections[0]).then(null, errorHandler);
Modal.remove();
}
}
});
};

$rootScope.removeRequestFromCollection = Collection.removeRequestFromCollection;

// Called when new urlVariables are added
$rootScope.newVariable = function() {
Expand All @@ -116,5 +79,10 @@ angular.module('RestedApp')
value: null
});
};

$rootScope.setTheme = function(theme) {
$rootScope.options.theme = theme;
DB.options.set({name: 'options', options: $rootScope.options}).then(null, errorHandler);
};
});

Loading

0 comments on commit afe872b

Please sign in to comment.