diff --git a/app/assets/js/start.js b/app/assets/js/start.js index 9b1b45ce..f801c645 100644 --- a/app/assets/js/start.js +++ b/app/assets/js/start.js @@ -12,4 +12,26 @@ $(function() { $('[data-toggle="tooltip"]').tooltip(); + $('button.close').on('click', function() { + $(this).parents('div.alert').addClass('hide'); + }); + + // Toggle inline component statuses. + $('form.component-inline').on('click', 'input[type=radio]', function() { + var $form = $(this).parents('form'); + var formData = $form.serializeObject(); + + $.ajax({ + async: true, + url: '/dashboard/api/components/' + formData['component_id'], + type: 'POST', + data: formData, + success: function(component) { + $('.alert').removeClass('hide'); + }, + error: function(a, b, c) { + alert('Something went wrong updating the component.'); + } + }); + }); }); diff --git a/app/controllers/DashAPIController.php b/app/controllers/DashAPIController.php new file mode 100644 index 00000000..80cc38a3 --- /dev/null +++ b/app/controllers/DashAPIController.php @@ -0,0 +1,23 @@ +update($componentData)) + { + return $component; + } + else + { + App::abort(500); + } + } +} diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index ffd9b641..642bfb2e 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -10,7 +10,10 @@ class DashboardController extends Controller public function showDashboard() { // TODO: Find steps needed to complete setup. - return View::make('dashboard.index'); + $components = Component::all(); + return View::make('dashboard.index')->with([ + 'components' => $components + ]); } /** diff --git a/app/routes/dashboard.php b/app/routes/dashboard.php index 913df89a..b4d5a447 100644 --- a/app/routes/dashboard.php +++ b/app/routes/dashboard.php @@ -33,4 +33,10 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function () { // User Settings Route::get('user', ['as' => 'dashboard.user', 'uses' => 'DashUserController@showUser']); Route::post('user', 'DashUserController@postUser'); + + // Internal API. + // This should only be used for making requests within the dashboard. + Route::group(['prefix' => 'api'], function() { + Route::post('components/{component}', 'DashAPIController@postUpdateComponent'); + }); }); diff --git a/app/views/dashboard/index.blade.php b/app/views/dashboard/index.blade.php index e224dfb5..37fa3bf1 100644 --- a/app/views/dashboard/index.blade.php +++ b/app/views/dashboard/index.blade.php @@ -9,7 +9,42 @@
-

Let's put cool things here.

+

Component Statuses

+
+
+ @forelse($components as $component) +
+ {{ Form::open(['class' => 'component-inline']) }} +
+
+ {{ $component->name }} +
+
+ @foreach(Lang::get('cachet.component.status') as $statusID => $status) +
+ +
+ @endforeach +
+
+ + {{ Form::close() }} +
+ @empty +
You should add a component.
+ @endforelse +
+
+ +
diff --git a/bower.json b/bower.json index 8120c45b..de5542b6 100644 --- a/bower.json +++ b/bower.json @@ -6,6 +6,7 @@ "chartjs": "0.2.*", "rivets": "0.7.*", "ionicons": "~2.0.0", - "jquery-minicolors": "2.1.10" + "jquery-minicolors": "2.1.10", + "jquery-serialize-object": "2.4.3" } } diff --git a/gulpfile.js b/gulpfile.js index 615f5099..a1d1c61f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -38,6 +38,7 @@ elixir(function (mix) { 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js', // 'bower_components/chartjs/Chart.min.js', 'bower_components/jquery-minicolors/jquery.minicolors.js', + 'bower_components/jquery-serialize-object/jquery.serialize-object.js', 'js/app.js', 'js/**/*.js', ], './app/assets/') diff --git a/public/build/js/all-fe283b26.js b/public/build/js/all-4554a981.js similarity index 97% rename from public/build/js/all-fe283b26.js rename to public/build/js/all-4554a981.js index c6c61ebe..c31cc155 100644 --- a/public/build/js/all-fe283b26.js +++ b/public/build/js/all-4554a981.js @@ -3156,6 +3156,159 @@ if(jQuery) (function($) { }); })(jQuery); +/** + * jQuery serializeObject + * @copyright 2014, macek + * @link https://github.com/macek/jquery-serialize-object + * @license BSD + * @version 2.4.3 + */ +(function(root, factory) { + + // AMD + if (typeof define === "function" && define.amd) { + define(["exports", "jquery"], function(exports, $) { + return factory(exports, $); + }); + } + + // CommonJS + else if (typeof exports !== "undefined") { + var $ = require("jquery"); + factory(exports, $); + } + + // Browser + else { + factory(root, (root.jQuery || root.Zepto || root.ender || root.$)); + } + +}(this, function(exports, $) { + + var patterns = { + validate: /^[a-z_][a-z0-9_]*(?:\[(?:\d*|[a-z0-9_]+)\])*$/i, + key: /[a-z0-9_]+|(?=\[\])/gi, + push: /^$/, + fixed: /^\d+$/, + named: /^[a-z0-9_]+$/i + }; + + function FormSerializer(helper, $form) { + + // private variables + var data = {}, + pushes = {}; + + // private API + function build(base, key, value) { + base[key] = value; + return base; + } + + function makeObject(root, value) { + + var keys = root.match(patterns.key), k; + + // nest, nest, ..., nest + while ((k = keys.pop()) !== undefined) { + // foo[] + if (patterns.push.test(k)) { + var idx = incrementPush(root.replace(/\[\]$/, '')); + value = build([], idx, value); + } + + // foo[n] + else if (patterns.fixed.test(k)) { + value = build([], k, value); + } + + // foo; foo[bar] + else if (patterns.named.test(k)) { + value = build({}, k, value); + } + } + + return value; + } + + function incrementPush(key) { + if (pushes[key] === undefined) { + pushes[key] = 0; + } + return pushes[key]++; + } + + function encode(pair) { + switch ($('[name="' + pair.name + '"]', $form).attr("type")) { + case "checkbox": + return pair.value === "on" ? true : pair.value; + default: + return pair.value; + } + } + + function addPair(pair) { + if (!patterns.validate.test(pair.name)) return this; + var obj = makeObject(pair.name, encode(pair)); + data = helper.extend(true, data, obj); + return this; + } + + function addPairs(pairs) { + if (!helper.isArray(pairs)) { + throw new Error("formSerializer.addPairs expects an Array"); + } + for (var i=0, len=pairs.length; i 1) { + return new Error("jquery-serialize-object can only serialize one form at a time"); + } + return new FormSerializer($, this). + addPairs(this.serializeArray()). + serialize(); + }; + + FormSerializer.serializeJSON = function serializeJSON() { + if (this.length > 1) { + return new Error("jquery-serialize-object can only serialize one form at a time"); + } + return new FormSerializer($, this). + addPairs(this.serializeArray()). + serializeJSON(); + }; + + if (typeof $.fn !== "undefined") { + $.fn.serializeObject = FormSerializer.serializeObject; + $.fn.serializeJSON = FormSerializer.serializeJSON; + } + + exports.FormSerializer = FormSerializer; + + return FormSerializer; +})); + $(function() { $('.color-code').minicolors({ @@ -3170,4 +3323,26 @@ $(function() { $('[data-toggle="tooltip"]').tooltip(); + $('button.close').on('click', function() { + $(this).parents('div.alert').addClass('hide'); + }); + + // Toggle inline component statuses. + $('form.component-inline').on('click', 'input[type=radio]', function() { + var $form = $(this).parents('form'); + var formData = $form.serializeObject(); + + $.ajax({ + async: true, + url: '/dashboard/api/components/' + formData['component_id'], + type: 'POST', + data: formData, + success: function(component) { + $('.alert').removeClass('hide'); + }, + error: function(a, b, c) { + alert('Something went wrong updating the component.'); + } + }); + }); }); diff --git a/public/build/js/all.js b/public/build/js/all.js index c6c61ebe..c31cc155 100644 --- a/public/build/js/all.js +++ b/public/build/js/all.js @@ -3156,6 +3156,159 @@ if(jQuery) (function($) { }); })(jQuery); +/** + * jQuery serializeObject + * @copyright 2014, macek + * @link https://github.com/macek/jquery-serialize-object + * @license BSD + * @version 2.4.3 + */ +(function(root, factory) { + + // AMD + if (typeof define === "function" && define.amd) { + define(["exports", "jquery"], function(exports, $) { + return factory(exports, $); + }); + } + + // CommonJS + else if (typeof exports !== "undefined") { + var $ = require("jquery"); + factory(exports, $); + } + + // Browser + else { + factory(root, (root.jQuery || root.Zepto || root.ender || root.$)); + } + +}(this, function(exports, $) { + + var patterns = { + validate: /^[a-z_][a-z0-9_]*(?:\[(?:\d*|[a-z0-9_]+)\])*$/i, + key: /[a-z0-9_]+|(?=\[\])/gi, + push: /^$/, + fixed: /^\d+$/, + named: /^[a-z0-9_]+$/i + }; + + function FormSerializer(helper, $form) { + + // private variables + var data = {}, + pushes = {}; + + // private API + function build(base, key, value) { + base[key] = value; + return base; + } + + function makeObject(root, value) { + + var keys = root.match(patterns.key), k; + + // nest, nest, ..., nest + while ((k = keys.pop()) !== undefined) { + // foo[] + if (patterns.push.test(k)) { + var idx = incrementPush(root.replace(/\[\]$/, '')); + value = build([], idx, value); + } + + // foo[n] + else if (patterns.fixed.test(k)) { + value = build([], k, value); + } + + // foo; foo[bar] + else if (patterns.named.test(k)) { + value = build({}, k, value); + } + } + + return value; + } + + function incrementPush(key) { + if (pushes[key] === undefined) { + pushes[key] = 0; + } + return pushes[key]++; + } + + function encode(pair) { + switch ($('[name="' + pair.name + '"]', $form).attr("type")) { + case "checkbox": + return pair.value === "on" ? true : pair.value; + default: + return pair.value; + } + } + + function addPair(pair) { + if (!patterns.validate.test(pair.name)) return this; + var obj = makeObject(pair.name, encode(pair)); + data = helper.extend(true, data, obj); + return this; + } + + function addPairs(pairs) { + if (!helper.isArray(pairs)) { + throw new Error("formSerializer.addPairs expects an Array"); + } + for (var i=0, len=pairs.length; i 1) { + return new Error("jquery-serialize-object can only serialize one form at a time"); + } + return new FormSerializer($, this). + addPairs(this.serializeArray()). + serialize(); + }; + + FormSerializer.serializeJSON = function serializeJSON() { + if (this.length > 1) { + return new Error("jquery-serialize-object can only serialize one form at a time"); + } + return new FormSerializer($, this). + addPairs(this.serializeArray()). + serializeJSON(); + }; + + if (typeof $.fn !== "undefined") { + $.fn.serializeObject = FormSerializer.serializeObject; + $.fn.serializeJSON = FormSerializer.serializeJSON; + } + + exports.FormSerializer = FormSerializer; + + return FormSerializer; +})); + $(function() { $('.color-code').minicolors({ @@ -3170,4 +3323,26 @@ $(function() { $('[data-toggle="tooltip"]').tooltip(); + $('button.close').on('click', function() { + $(this).parents('div.alert').addClass('hide'); + }); + + // Toggle inline component statuses. + $('form.component-inline').on('click', 'input[type=radio]', function() { + var $form = $(this).parents('form'); + var formData = $form.serializeObject(); + + $.ajax({ + async: true, + url: '/dashboard/api/components/' + formData['component_id'], + type: 'POST', + data: formData, + success: function(component) { + $('.alert').removeClass('hide'); + }, + error: function(a, b, c) { + alert('Something went wrong updating the component.'); + } + }); + }); }); diff --git a/public/build/rev-manifest.json b/public/build/rev-manifest.json index 1c9b01d6..e020bbe1 100644 --- a/public/build/rev-manifest.json +++ b/public/build/rev-manifest.json @@ -1,4 +1,4 @@ { "css/all.css": "css/all-729d9f2f.css", - "js/all.js": "js/all-fe283b26.js" + "js/all.js": "js/all-4554a981.js" } \ No newline at end of file