Skip to content

Commit

Permalink
Merge pull request #34 from kabukky/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
kabukky committed May 6, 2015
2 parents f9115f6 + a34b6fd commit c5b7cbc
Show file tree
Hide file tree
Showing 27 changed files with 566 additions and 248 deletions.
66 changes: 58 additions & 8 deletions built-in/admin/admin-angular.js
@@ -1,5 +1,6 @@
//register the modules (don't forget ui bootstrap and bootstrap switch)
var adminApp = angular.module('adminApp', ['ngRoute', 'frapontillo.bootstrap-switch', 'ui.bootstrap', 'infinite-scroll']);

adminApp.config(function($routeProvider) {
$routeProvider.
when('/', {
Expand Down Expand Up @@ -35,14 +36,34 @@ adminApp.directive('imgSelectionDirective', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
$(elem).click(function() {
$('.imgselected').removeClass('imgselected');
$(elem).children('img').addClass('imgselected');
});
$(elem).click(function() {
$('.imgselected').removeClass('imgselected');
$(elem).children('img').addClass('imgselected');
});
}
}
});

//directive to add/remove the blog url to/from the navigation url fields
adminApp.directive('evaluateUrl', function() {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
elem.on('blur', function() {
var value = elem.val();
//if the url of this item doesn't start with http/https, add the blog url to it.
if (!(value.substring(0, 'http://'.length) === 'http://') && !(value.substring(0, 'https://'.length) === 'https://') && !(value.substring(0, scope.shared.blog.Url.length) === scope.shared.blog.Url)) {
if ((value.substring(0, 1) != '/') && (scope.shared.blog.Url.slice(-1) != '/')) {
value = '/' + value;
}
value = scope.shared.blog.Url + value;
elem.val(value);
}
});
}
};
});

//factory to load items in infinite-scroll
adminApp.factory('infiniteScrollFactory', function($http) {
var infiniteScrollFactory = function(url) {
Expand Down Expand Up @@ -70,7 +91,7 @@ adminApp.factory('infiniteScrollFactory', function($http) {

adminApp.controller('ContentCtrl', function ($scope, $http, $sce, $location, infiniteScrollFactory, sharingService){
//change the navbar according to controller
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li class="active"><a href="#/">Content<span class="sr-only">(current)</span></a></li><li><a href="#/create/">New Post</a></li><li><a href="#/settings/">Settings</a></li></ul>');
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li class="active"><a href="#/">Content<span class="sr-only">(current)</span></a></li><li><a href="#/create/">New Post</a></li><li><a href="#/settings/">Settings</a></li><li><a href="logout/" class="logout">Log Out</a></li></ul>');
$scope.infiniteScrollFactory = new infiniteScrollFactory('/admin/api/posts/');
$scope.openPost = function(postId) {
$location.url('/edit/' + postId);
Expand All @@ -91,13 +112,32 @@ adminApp.controller('ContentCtrl', function ($scope, $http, $sce, $location, inf

adminApp.controller('SettingsCtrl', function ($scope, $http, $timeout, $sce, $location, sharingService){
//change the navbar according to controller
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li><a href="#/create/">New Post</a></li><li class="active"><a href="#/settings/">Settings<span class="sr-only">(current)</span></a></li></ul>');
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li><a href="#/create/">New Post</a></li><li class="active"><a href="#/settings/">Settings<span class="sr-only">(current)</span></a></li><li><a href="logout/" class="logout">Log Out</a></li></ul>');
$scope.shared = sharingService.shared;
//variable to hold the field prefix
$scope.prefix = '';
$scope.loadData = function() {
$http.get('/admin/api/blog').success(function(data) {
$scope.shared.blog = data;
//select active theme
var themeIndex = $scope.shared.blog.Themes.indexOf($scope.shared.blog.ActiveTheme);
$scope.shared.blog.ActiveTheme = $scope.shared.blog.Themes[themeIndex];
//make sure NavigationItems is not null
if ($scope.shared.blog.NavigationItems == null) {
$scope.shared.blog.NavigationItems = []
}
//append the blog url to the navigation items if necessary
for (var i = 0; i < $scope.shared.blog.NavigationItems.length; i++) {
var value = $scope.shared.blog.NavigationItems[i].url;
//if the url of this item doesn't start with http/https, add the blog url to it.
if (!(value.substring(0, 'http://'.length) === 'http://') && !(value.substring(0, 'https://'.length) === 'https://') && !(value.substring(0, $scope.shared.blog.Url.length) === $scope.shared.blog.Url)) {
if ((value.substring(0, 1) != '/') && ($scope.shared.blog.Url.slice(-1) != '/')) {
value = '/' + value;
}
value = $scope.shared.blog.Url + value;
$scope.shared.blog.NavigationItems[i].url = value;
}
}
});
$http.get('/admin/api/userid').success(function(data) {
$scope.authenticatedUser = data;
Expand All @@ -107,6 +147,16 @@ adminApp.controller('SettingsCtrl', function ($scope, $http, $timeout, $sce, $lo
});
};
$scope.loadData();
$scope.deleteNavItem = function(index) {
$scope.shared.blog.NavigationItems.splice(index, 1);
};
$scope.addNavItem = function() {
var url = $scope.shared.blog.Url
if (url.slice(-1) != '/') {
url = url + '/';
}
$scope.shared.blog['NavigationItems'].push({label: 'Home', url: url});
};
$scope.save = function() {
$http.patch('/admin/api/blog', $scope.shared.blog);
$http.patch('/admin/api/user', $scope.shared.user).success(function(data) {
Expand All @@ -119,7 +169,7 @@ adminApp.controller('CreateCtrl', function ($scope, $http, $sce, $location, shar
//create markdown converter
var converter = new Showdown.converter();
//change the navbar according to controller
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li class="active"><a href="#/create/">New Post<span class="sr-only">(current)</span></a></li><li><a href="#/settings/">Settings</a></li></ul>');
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li class="active"><a href="#/create/">New Post<span class="sr-only">(current)</span></a></li><li><a href="#/settings/">Settings</a></li><li><a href="logout/" class="logout">Log Out</a></li></ul>');
$scope.shared = sharingService.shared;
$scope.shared.post = {Title: 'New Post', Slug: '', Markdown: 'Write something!', IsPublished: false, Image: '', Tags: ''}
$scope.change = function() {
Expand All @@ -139,7 +189,7 @@ adminApp.controller('EditCtrl', function ($scope, $routeParams, $http, $sce, $lo
//create markdown converter
var converter = new Showdown.converter();
//change the navbar according to controller
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li><a href="#/create/">New Post</a></li><li><a href="#/settings/">Settings</a></li></ul>');
$scope.navbarHtml = $sce.trustAsHtml('<ul class="nav navbar-nav"><li><a href="#/">Content</a></li><li><a href="#/create/">New Post</a></li><li><a href="#/settings/">Settings</a></li><li><a href="logout/" class="logout">Log Out</a></li></ul>');
$scope.shared = sharingService.shared;
$scope.shared.post = {}
$scope.change = function() {
Expand Down
13 changes: 13 additions & 0 deletions built-in/admin/admin.css
Expand Up @@ -65,6 +65,10 @@ img {
margin-right: 15px;
}

.logout {
color: #f04124 !important;
}

.post-content-row {
cursor: pointer;
}
Expand Down Expand Up @@ -147,4 +151,13 @@ img {
.navbar-label-text {
font-size: 16px;
color: #ffffff;
}

.navigation-item {
padding-top: 10px;
padding-bottom: 10px;
background-color: #f8f8f8;
outline: 1px solid #dddddd;
margin-right: 0 !important;
margin-left: 0 !important;
}
2 changes: 2 additions & 0 deletions built-in/admin/login.html
Expand Up @@ -4,6 +4,8 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Admin Area</title>
<!-- JQuery JavaScript -->
<script src="/public/jquery/jquery.min.js"></script>
<!-- Bootstrap CSS and JavaScript -->
<link rel="stylesheet" href="/public/bootstrap/css/bootstrap.yeti.min.css">
<script src="/public/bootstrap/js/bootstrap.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion built-in/admin/post.html
Expand Up @@ -64,7 +64,7 @@
</form>
</div>
<form class="navbar-form save-button-navbar" role="form">
<button type="button" class="btn btn-primary" id="post-save-button" ng-click="save()">Save</button>
<button type="button" class="btn btn-primary" id="post-save-button" ng-click="save()">Save</button>
</form>
</div>
</div>
Expand Down
31 changes: 30 additions & 1 deletion built-in/admin/settings.html
Expand Up @@ -55,6 +55,35 @@ <h1>Blog</h1>
</div>
</div>
</form>
<div class="page-header">
<h1>Navigation</h1>
</div>
<form class="form-horizontal">
<div class="form-group navigation-item" ng-repeat="navItem in shared.blog.NavigationItems">
<div class="col-sm-6">
<div class="row">
<label for="navigation-label" class="col-sm-2 col-sm-offset-2 control-label">Label</label>
<div class="col-sm-8">
<input type="text" class="form-control" ng-model="navItem.label" value="{{navItem.label}}">
</div>
</div>
<div class="row">
<label for="navigation-url" class="col-sm-2 col-sm-offset-2 control-label">Url</label>
<div class="col-sm-8">
<input evaluate-url type="text" class="form-control" ng-model="navItem.url" value="{{navItem.url}}">
</div>
</div>
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-danger" id="delete-navigation-row" ng-click="deleteNavItem($index)">− Item</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-2 col-sm-offset-2">
<button type="button" class="btn btn-success" id="add-navigation-row" ng-click="addNavItem()">+ Item</button>
</div>
</div>
</form>
<div class="page-header">
<h1>User {{shared.user.Name}}</h1>
</div>
Expand Down Expand Up @@ -113,7 +142,7 @@ <h1>User {{shared.user.Name}}</h1>
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container-fluid">
<form class="navbar-form save-button-navbar" role="form">
<button type="button" class="btn btn-primary" id="settings-save-button" ng-click="save()">Save</button>
<button type="button" class="btn btn-primary" id="settings-save-button" ng-click="save()">Save</button>
</form>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions built-in/hbs/navigation.hbs
@@ -0,0 +1,5 @@
<ul class="nav">
{{#foreach navigation}}
<li class="nav-{{slug}}{{#if current}} nav-current{{/if}}" role="presentation"><a href="{{url absolute="true"}}">{{label}}</a></li>
{{/foreach}}
</ul>
9 changes: 9 additions & 0 deletions built-in/hbs/pagination.hbs
@@ -0,0 +1,9 @@
<nav class="pagination" role="navigation">
{{#if prev}}
<a class="newer-posts" href="{{page_url prev}}">&larr; Newer Posts</a>
{{/if}}
<span class="page-number">Page {{page}} of {{pages}}</span>
{{#if next}}
<a class="older-posts" href="{{page_url next}}">Older Posts &rarr;</a>
{{/if}}
</nav>
8 changes: 7 additions & 1 deletion config.json
@@ -1 +1,7 @@
{"HttpHostAndPort":":8084","HttpsHostAndPort":":8085","HttpsUsage":"None","Url":"http://127.0.0.1:8084","HttpsUrl":"https://127.0.0.1:8085"}
{
"HttpHostAndPort":":8084",
"HttpsHostAndPort":":8085",
"HttpsUsage":"None",
"Url":"http://127.0.0.1:8084",
"HttpsUrl":"https://127.0.0.1:8085"
}
78 changes: 40 additions & 38 deletions database/initialization.go
Expand Up @@ -10,69 +10,70 @@ import (
"time"
)

var readDB *sql.DB // Handler for read access
// Handler for read access
var readDB *sql.DB

var stmtInitialization = `CREATE TABLE IF NOT EXISTS
posts (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
uuid varchar(36) NOT NULL,
title varchar(150) NOT NULL,
title varchar(150) NOT NULL,
slug varchar(150) NOT NULL,
markdown text,
html text,
image text,
image text,
featured tinyint NOT NULL DEFAULT '0',
page tinyint NOT NULL DEFAULT '0',
status varchar(150) NOT NULL DEFAULT 'draft',
status varchar(150) NOT NULL DEFAULT 'draft',
language varchar(6) NOT NULL DEFAULT 'en_US',
meta_title varchar(150),
meta_title varchar(150),
meta_description varchar(200),
author_id integer NOT NULL,
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer,
author_id integer NOT NULL,
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer,
published_at datetime,
published_by integer
);
CREATE TABLE IF NOT EXISTS
users (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
uuid varchar(36) NOT NULL,
name varchar(150) NOT NULL,
slug varchar(150) NOT NULL,
password varchar(60) NOT NULL,
email varchar(254) NOT NULL,
image text,
cover text,
bio varchar(200),
website text,
email varchar(254) NOT NULL,
image text,
cover text,
bio varchar(200),
website text,
location text,
accessibility text,
status varchar(150) NOT NULL DEFAULT 'active',
accessibility text,
status varchar(150) NOT NULL DEFAULT 'active',
language varchar(6) NOT NULL DEFAULT 'en_US',
meta_title varchar(150),
meta_title varchar(150),
meta_description varchar(200),
last_login datetime,
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer
last_login datetime,
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer
);
CREATE TABLE IF NOT EXISTS
tags (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
uuid varchar(36) NOT NULL,
name varchar(150) NOT NULL,
slug varchar(150) NOT NULL,
description varchar(200),
parent_id integer,
meta_title varchar(150),
description varchar(200),
parent_id integer,
meta_title varchar(150),
meta_description varchar(200),
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
updated_by integer
);
CREATE TABLE IF NOT EXISTS
posts_tags (
Expand All @@ -83,10 +84,10 @@ var stmtInitialization = `CREATE TABLE IF NOT EXISTS
CREATE TABLE IF NOT EXISTS
settings (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
uuid varchar(36) NOT NULL,
uuid varchar(36) NOT NULL,
key varchar(150) NOT NULL,
value text,
type varchar(150) NOT NULL DEFAULT 'core',
type varchar(150) NOT NULL DEFAULT 'core',
created_at datetime NOT NULL,
created_by integer NOT NULL,
updated_at datetime,
Expand All @@ -99,11 +100,12 @@ var stmtInitialization = `CREATE TABLE IF NOT EXISTS
INSERT OR IGNORE INTO settings (id, uuid, key, value, type, created_at, created_by, updated_at, updated_by) VALUES (5, ?, 'cover', '/public/images/blog-cover.jpg', 'blog', ?, 1, ?, 1);
INSERT OR IGNORE INTO settings (id, uuid, key, value, type, created_at, created_by, updated_at, updated_by) VALUES (6, ?, 'postsPerPage', 5, 'blog', ?, 1, ?, 1);
INSERT OR IGNORE INTO settings (id, uuid, key, value, type, created_at, created_by, updated_at, updated_by) VALUES (7, ?, 'activeTheme', 'promenade', 'theme', ?, 1, ?, 1);
INSERT OR IGNORE INTO settings (id, uuid, key, value, type, created_at, created_by, updated_at, updated_by) VALUES (8, ?, 'navigation', '[{"label":"Home", "url":"/"}]', 'blog', ?, 1, ?, 1);
CREATE TABLE IF NOT EXISTS
roles (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
uuid varchar(36) NOT NULL,
name varchar(150) NOT NULL,
uuid varchar(36) NOT NULL,
name varchar(150) NOT NULL,
description varchar(200),
created_at datetime NOT NULL,
created_by integer NOT NULL,
Expand Down Expand Up @@ -140,7 +142,7 @@ func Initialize() error {
return err
}
currentTime := time.Now()
_, err = readDB.Exec(stmtInitialization, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime)
_, err = readDB.Exec(stmtInitialization, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), currentTime, currentTime)
// TODO: Is Commit()/Rollback() needed for DB.Exec()?
if err != nil {
return err
Expand Down

0 comments on commit c5b7cbc

Please sign in to comment.