From 5803cfc798e9199c9b5d832c9a000578d6f55644 Mon Sep 17 00:00:00 2001 From: Paul V Moreau Date: Wed, 3 Feb 2016 08:16:48 -0600 Subject: [PATCH] added addEntry page with skeletal functionality. --- index.html | 10 ++-- js/controllers/addEntry.js | 23 +++++++++ js/controllers/indexView.js | 26 ++++++++++ js/directives/brewEntry.js | 9 ++++ js/module.js | 10 ++-- js/services/cauldronAPI.js | 63 +++++++++++++++++++++++++ views/addEntry.html | 23 +++++++++ {js => views}/directives/brewEntry.html | 6 +-- views/indexView.html | 6 +-- 9 files changed, 161 insertions(+), 15 deletions(-) create mode 100644 js/controllers/addEntry.js create mode 100644 js/controllers/indexView.js create mode 100644 js/directives/brewEntry.js create mode 100644 js/services/cauldronAPI.js create mode 100644 views/addEntry.html rename {js => views}/directives/brewEntry.html (57%) diff --git a/index.html b/index.html index 382b627..75cb968 100644 --- a/index.html +++ b/index.html @@ -18,13 +18,13 @@ - Brand + Cauldron 0.1 @@ -38,5 +38,9 @@ + + + + diff --git a/js/controllers/addEntry.js b/js/controllers/addEntry.js new file mode 100644 index 0000000..5de9112 --- /dev/null +++ b/js/controllers/addEntry.js @@ -0,0 +1,23 @@ +angular.module('cauldron') +.controller('addEntry', ['cauldronAPI','$scope','$q', function(cauldronAPI, $scope, $q){ + var tagsList = cauldronAPI.getTags(); + + var submitEntry = function(){ + var newEntry = $scope.entryData; + newEntry.author = { + username: 'Megaman '+ Math.random(), + display_name: 'The_dude' + Math.random(), + email:'Mega' + Math.random() + '@fakemeail.com' + }; + newEntry.version = '1.0'; + newEntry.links = ['megaLinks.com', 'UltimateLink.org']; + var promise = cauldronAPI.addEntry(newEntry); + + promise.then(function(response){ + console.log('Entry Added, redirecting back to index'); + }, + function(response) { + console.log('something went wrong', response); + }); + } +}]); diff --git a/js/controllers/indexView.js b/js/controllers/indexView.js new file mode 100644 index 0000000..8361ecb --- /dev/null +++ b/js/controllers/indexView.js @@ -0,0 +1,26 @@ +angular.module('cauldron') +.controller('indexView', ['cauldronAPI','$scope','$q', function(cauldronAPI, $scope, $q){ + console.log('indexView controller checking in'); + + var setIndexEntries = function(){ + var promise = cauldronAPI.getEntries(); + promise.then(function(response){ + $scope.indexEntries = response; + }, + function(response) { + console.log('something went wrong', response); + }); + + } + setIndexEntries(); + + $scope.addNew = function(){ + var promise = cauldronAPI.addEntry(); + promise.then(function(response){ + setIndexEntries(); + }, + function(response) { + console.log('something went wrong', response); + }); + } +}]); diff --git a/js/directives/brewEntry.js b/js/directives/brewEntry.js new file mode 100644 index 0000000..bfcee74 --- /dev/null +++ b/js/directives/brewEntry.js @@ -0,0 +1,9 @@ +angular.module('cauldron').directive('brewEntry', function() { + + return { + templateUrl: '/views/directives/brewEntry.html', + scope: { + entryData: '=brew', + } + }; +}); diff --git a/js/module.js b/js/module.js index d2d9fb7..d2fd152 100644 --- a/js/module.js +++ b/js/module.js @@ -3,14 +3,14 @@ angular.module("cauldron", ['ngRoute']) function($routeProvider){ $routeProvider.when('/',{ templateUrl:'/views/indexView.html', + controller:'indexView' + }) + .when('/addEntry',{ + templateUrl:'/views/addEntry.html', + controller:'addEntry' }) .otherwise({ redirectTo: '/', }); } ]) -.directive('brewEntry', function() { - return { - templateUrl: '/js/directives/brewEntry.html' - }; -}); diff --git a/js/services/cauldronAPI.js b/js/services/cauldronAPI.js new file mode 100644 index 0000000..ec4f200 --- /dev/null +++ b/js/services/cauldronAPI.js @@ -0,0 +1,63 @@ +angular.module('cauldron') +.service('cauldronAPI',[ '$http','$q', function($http, $q){ + var backendURL = 'http://localhost:1337'; + + var connect = function(){ + console.log("Connected!"); + }; + + var getTags = function(){ + console.log('Tags backend not implemented'); + } + + var addEntry = function(params){ + + if(typeof params === 'undefined'){ + var params = { + title: 'Test Title ' + Math.random(), + description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', + author: { + username: 'Jim Beam '+ Math.random(), + display_name: 'Jimmy' + Math.random(), + email:'Jim' + Math.random() + '@fakemeail.com' + }, + version: '1.0', + links: ['fakelink.com'], + //system: ['Pathfinder'], + //tags: ['Scenario'], + }; + } + return $http({ + method: 'POST', + url: backendURL +'/brew', + data: { + title: params.title, + description: params.description, + author: params.author, + version: params.version, + links: params.links, + system: params.system, + tags: params.tags + } + }).then(function successCallback(response) { + return response.data; + }, function errorCallback(response) { + console.log('FAIL!', response); + }); + }; + + var getEntries = function(){ + return $http({ + method: 'GET', + url: backendURL+'/brew', + }).then(function(response){ + return response.data; + }); + }; + + return { + connect: connect, + addEntry:addEntry, + getEntries:getEntries, + } +}]); diff --git a/views/addEntry.html b/views/addEntry.html new file mode 100644 index 0000000..30ca8cf --- /dev/null +++ b/views/addEntry.html @@ -0,0 +1,23 @@ +
+
+ + +
+
+ + +
+
+
+ + +
We ain't goin' to host your shit
+
+
+ + +
+
+ +
+
diff --git a/js/directives/brewEntry.html b/views/directives/brewEntry.html similarity index 57% rename from js/directives/brewEntry.html rename to views/directives/brewEntry.html index ddabc27..bf237e3 100644 --- a/js/directives/brewEntry.html +++ b/views/directives/brewEntry.html @@ -4,9 +4,9 @@
This Is the System
-

This is H3 Title

-
h6 author
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

+

{{entryData.title}}

+
{{entryData.author[0].username}}
+

{{entryData.description}}