Skip to content

Commit

Permalink
Prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
deanoemcke committed Nov 22, 2019
1 parent d375cca commit a0cdf56
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 119 deletions.
1 change: 0 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ span,
applet,
object,
iframe,
,
h2,
h3,
h4,
Expand Down
130 changes: 67 additions & 63 deletions js/dbService.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
/*global chrome, localStorage */
(function (window) {

(function(window) {
'use strict';

var dbService = {

DB_SERVER: 'spaces',
DB_VERSION: '1',
DB_SESSIONS: 'ttSessions',

noop: function() {},


/**
* INDEXEDDB FUNCTIONS
*/
/**
* INDEXEDDB FUNCTIONS
*/
getDb: function() {
var self = this;
return db.open({
server: self.DB_SERVER,
version: self.DB_VERSION,
schema: self.getSchema
schema: self.getSchema,
});
},

/**
* Properties of a session object
* session.id: auto-generated indexedDb object id
* session.sessionHash: a hash formed from the combined urls in the session window
* session.name: the saved name of the session
* session.tabs: an array of chrome tab objects (often taken from the chrome window obj)
* session.history: an array of chrome tab objects that have been removed from the session
* session.lastAccess: timestamp that gets updated with every window focus
*/
/**
* Properties of a session object
* session.id: auto-generated indexedDb object id
* session.sessionHash: a hash formed from the combined urls in the session window
* session.name: the saved name of the session
* session.tabs: an array of chrome tab objects (often taken from the chrome window obj)
* session.history: an array of chrome tab objects that have been removed from the session
* session.lastAccess: timestamp that gets updated with every window focus
*/
getSchema: function() {
return {
ttSessions: {
key: {
keyPath: 'id',
autoIncrement: true
autoIncrement: true,
},
indexes: {
id: {}
}
}
id: {},
},
},
};
},

_fetchAllSessions: function() {
var self = this;
return this.getDb().then(function (s) {
return s.query(self.DB_SESSIONS).all().execute();
return this.getDb().then(function(s) {
return s
.query(self.DB_SESSIONS)
.all()
.execute();
});
},

_fetchSessionById: function(id) {
var self = this;

id = typeof id === 'string' ? parseInt(id, 10) : id;
return this.getDb().then(function (s) {
return s.query(self.DB_SESSIONS, 'id' )
.only(id)
.distinct()
.desc()
.execute()
.then(function(results) {
return results.length > 0 ? results[0] : null;
});
return this.getDb().then(function(s) {
return s
.query(self.DB_SESSIONS, 'id')
.only(id)
.distinct()
.desc()
.execute()
.then(function(results) {
return results.length > 0 ? results[0] : null;
});
});
},

Expand All @@ -89,22 +90,25 @@
callback = typeof callback !== 'function' ? this.noop : callback;

this._fetchAllSessions().then(function(sessions) {
callback(sessions.map(function(session) {
return session.name;
}));
callback(
sessions.map(function(session) {
return session.name;
})
);
});
},

fetchSessionByName: function(sessionName, callback) {

var self = this,
matchFound,
matchIndex;
callback = typeof callback !== 'function' ? this.noop : callback;

this._fetchAllSessions().then(function(sessions) {
matchFound = sessions.some(function (session, index) {
if(session.name.toLowerCase() === sessionName.toLowerCase()) {
matchFound = sessions.some(function(session, index) {
if (
session.name.toLowerCase() === sessionName.toLowerCase()
) {
matchIndex = index;
return true;
}
Expand All @@ -119,25 +123,24 @@
},

createSession: function(session, callback) {

var self = this;
callback = typeof callback !== 'function' ? this.noop : callback;

//delete session id in case it already exists
delete session.id;

this.getDb().then(function (s) {
return s.add(self.DB_SESSIONS, session);

}).then(function(result) {
if (result.length > 0) {
callback(result[0]);
}
});
this.getDb()
.then(function(s) {
return s.add(self.DB_SESSIONS, session);
})
.then(function(result) {
if (result.length > 0) {
callback(result[0]);
}
});
},

updateSession: function(session, callback) {

var self = this;
callback = typeof callback !== 'function' ? this.noop : callback;

Expand All @@ -147,28 +150,29 @@
return;
}

this.getDb().then(function (s) {
return s.update(self.DB_SESSIONS, session);

}).then(function(result) {
if (result.length > 0) {
callback(result[0]);
}
});
this.getDb()
.then(function(s) {
return s.update(self.DB_SESSIONS, session);
})
.then(function(result) {
if (result.length > 0) {
callback(result[0]);
}
});
},

removeSession: function(id, callback) {

var self = this;
id = typeof id === 'string' ? parseInt(id, 10) : id;
callback = typeof callback !== 'function' ? this.noop : callback;

this.getDb().then(function (s) {
return s.remove(self.DB_SESSIONS , id);
}).then(callback);
}
this.getDb()
.then(function(s) {
return s.remove(self.DB_SESSIONS, id);
})
.then(callback);
},
};

window.dbService = dbService;

}(window));
})(window);
116 changes: 61 additions & 55 deletions spaces.html
Original file line number Diff line number Diff line change
@@ -1,82 +1,88 @@
<!doctype html>
<html>

<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,300,600,400' rel='stylesheet' type='text/css'>
<title id='gsTitle'>Spaces</title>
<link type="text/css" href="css/style.css" rel="stylesheet"></link>
<link type="text/css" href="css/style.css" rel="stylesheet">
</link>
<script type="text/javascript" src="js/spaces.js"></script>

</head>

<body>

<div class="mainContent">
<div class="mainContent">

<div class="contentNav">
<div class="contentNav">

<div class="header">
<a id="spacesHome" href="#">
<img src="img/icon48.png" />
<h1>Spaces</h1>
</a>
</div>
<div class="header">
<a id="spacesHome" href="#">
<img src="img/icon48.png" />
<h1>Spaces</h1>
</a>
</div>

<div class="contentBody">
<h2>Open spaces:</h2>
<ul id="openSpaces"></ul>
<h2>Closed spaces:</h2>
<ul id="closedSpaces"></ul>
<ul>
<li><a id="actionImport" href="#">Import spaces or urls...</a></li>
<li><a id="actionBackup" href="#">Backup all spaces...</a></li>
</ul>
<div class="contentBody">
<h2>Open spaces:</h2>
<ul id="openSpaces"></ul>
<h2>Closed spaces:</h2>
<ul id="closedSpaces"></ul>
<ul>
<li><a id="actionImport" href="#">Import spaces or urls...</a></li>
<li><a id="actionBackup" href="#">Backup all spaces...</a></li>
</ul>
</div>
</div>
</div>

<div class="content">
<div class="content">

<div class="header">
<form id="nameForm">
<span id="nameDisplay"></span>
<input type="text" placeholder="Name this space" />
</form>
<span id='actionSwitch' title="Switch to this space" class="button fa fa-arrow-circle-right"></span>
<span id='actionOpen' title="Open this space" class="button fa fa-external-link"></span>
<div class="buttonNav">
<span id='actionEdit' title="Rename space" class="button fa fa-pencil"></span>
<span id='actionExport' title="Export space" class="button fa fa-download"></span>
<span id='actionDelete' title="Delete space" class="button fa fa-trash"></span>
<div class="header">
<form id="nameForm">
<span id="nameDisplay"></span>
<input type="text" placeholder="Name this space" />
</form>
<span id='actionSwitch' title="Switch to this space" class="button fa fa-arrow-circle-right"></span>
<span id='actionOpen' title="Open this space" class="button fa fa-external-link"></span>
<div class="buttonNav">
<span id='actionEdit' title="Rename space" class="button fa fa-pencil"></span>
<span id='actionExport' title="Export space" class="button fa fa-download"></span>
<span id='actionDelete' title="Delete space" class="button fa fa-trash"></span>
</div>
</div>
</div>

<div class="contentBody">
<h2>Active tabs:</h2>
<ul id="activeTabs" class="tabsList"></ul>
<h2>Recently closed tabs:</h2>
<ul id="historicalTabs" class="tabsList"></ul>
<div class="contentBody">
<h2>Active tabs:</h2>
<ul id="activeTabs" class="tabsList"></ul>
<h2>Recently closed tabs:</h2>
<ul id="historicalTabs" class="tabsList"></ul>
</div>
</div>
</div>

<div id="banner" class="hidden">
<div id="lessonOne">
<h1>Welcome to Spaces!</h1>
<p >Get started by naming your open spaces.<br />
To create new spaces simply open a new chrome window.</p>
<div id="banner" class="hidden">
<div id="lessonOne">
<h1>Welcome to Spaces!</h1>
<p>Get started by naming your open spaces.<br />
To create new spaces simply open a new chrome window.</p>
</div>
<div id="lessonTwo">
<h1>Great!</h1>
<p>To access this screen and other features while browsing, click the spaces icon in your browser.<br />
Thanks for trying Spaces :)</p>
</div>
</div>
<div id="lessonTwo">
<h1>Great!</h1>
<p>To access this screen and other features while browsing, click the spaces icon in your browser.<br />
Thanks for trying Spaces :)</p>

<div class="blocker"></div>
<div class="modal">
<h2>Import a new space</h2>
<textarea id="importTextArea" spellcheck="false"
placeholder="Paste a list of line-separated urls or the contents of a spaces backup file" wrap="off"
rows="10"></textarea>
<a id="importBtn" class="button" href="#">Import</a>
</div>
</div>

<div class="blocker"></div>
<div class="modal">
<h2>Import a new space</h2>
<textarea id="importTextArea" spellcheck="false" placeholder="Paste a list of line-separated urls or the contents of a spaces backup file" wrap="off" rows="10"></textarea>
<a id="importBtn" class="button" href="#">Import</a>
</div>

</div>
</body>

</html>

0 comments on commit a0cdf56

Please sign in to comment.