Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
add option to enable/disable auto removal and force networking
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Verstraeten committed Jun 30, 2017
1 parent d165d80 commit bd891f6
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 19 deletions.
11 changes: 8 additions & 3 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace App\Http\Controllers;

use App, View, Config;
use App, View, Config, Session;
use App\Http\Repositories\ImageHandler\ImageHandlerInterface as ImageHandlerInterface;
use App\Http\Repositories\ConfigReader\ConfigReaderInterface as ConfigReaderInterface;

Expand All @@ -12,7 +12,12 @@ public function __construct(ImageHandlerInterface $imageHandler, ConfigReaderInt
$this->imageHandler = $imageHandler;
$this->reader = $reader;
$this->config = Config::get("app.config");
$this->kerberos = Config::get("kerberos");
$this->kerberos = Session::get('kerberos', []);
if(count($this->kerberos) == 0)
{
$this->kerberos = Config::get("kerberos");
Session::put('kerberos', $this->kerberos);
}
}

/****************************
Expand All @@ -24,7 +29,7 @@ public function index()
// Get last x days from the imagehandler -> move to BaseController

$days = $this->imageHandler->getDays(5);

$directory = $this->config;
$settings = $this->reader->parse($directory)["instance"]["children"];

Expand Down
91 changes: 90 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ public function index()

$days = $this->imageHandler->getDays(5);

$kios = null;
if($this->isKios())
{
$kios = [
'autoremoval' => $this->getAutoRemoval(),
'forcenetwork' => $this->getForceNetwork(),
];
}

return View::make('settings',
[
'cameraName' => $settings['name']['value'],
'days' => $days,
'settings' => $settings,
'kerberos' => $this->kerberos
'kerberos' => $this->kerberos,
'kios' => $kios
]);
}

Expand Down Expand Up @@ -353,4 +363,83 @@ public function updateIoWebhook()

return $this->getIoWebhook();
}

// -------------------------------------------
// Duplicate functions with OSsystem.php class,
// TODO: refactor these methods.

public function getBoard()
{
$cmd = 'cat /etc/board';
$board = shell_exec($cmd);
return trim($board);
}

public function isKios()
{
return ($this->getBoard()!='');
}

//
// -------------------------

public function getForceNetwork()
{
$cmd = 'cat /data/etc/watch.conf | grep "netwatch_enable"';
$forcenetwork = shell_exec($cmd);

if($forcenetwork && $forcenetwork !== '')
{
$parameter = explode('=', $forcenetwork);
$active = (str_replace("\n", '', $parameter[1]) === 'yes');
}

return $active;
}

public function updateForceNetwork()
{
$active = (Input::get('active') === "true") ? "yes" : "no";
$currentState = ($this->getForceNetwork()) ? "yes" : "no";

if($active !== $currentState)
{
$old = "netwatch_enable\=$currentState";
$new = "netwatch_enable\=$active";
shell_exec("sed -i 's/$old/$new/g' /data/etc/watch.conf");
return ['active' => $active];
}

return ['active' => $currentState];
}

public function getAutoRemoval()
{
$cmd = 'cat /data/etc/watch.conf | grep "autoremoval"';
$autoremoval = shell_exec($cmd);

if($autoremoval && $autoremoval !== '')
{
$parameter = explode('=', $autoremoval);
$active = (str_replace("\n", '', $parameter[1]) === 'yes');
}

return $active;
}

public function updateAutoRemoval()
{
$active = (Input::get('active') === "true") ? "yes" : "no";
$currentState = ($this->getAutoRemoval()) ? "yes" : "no";

if($active !== $currentState)
{
$old = "autoremoval\=$currentState";
$new = "autoremoval\=$active";
shell_exec("sed -i 's/$old/$new/g' /data/etc/watch.conf");
return ['active' => $active];
}

return ['active' => $currentState];
}
}
9 changes: 8 additions & 1 deletion public/css/kerberos.css
Original file line number Diff line number Diff line change
Expand Up @@ -9999,13 +9999,20 @@ div.video-preview video:first-child {
.tgl-ios:checked + .tgl-btn {
background: #f1f1f1;
}
#kios-configuration .tgl-ios:checked + .tgl-btn {
background-color: #943633;
}
#update-profile-modal {
min-width: 600px;
}
#machinery-settings,
#web-settings {
padding-right: 30px;
}
.switch-light span span,
.switch-light a {
outline: none !important;
}
#web-settings .content {
display: table;
clear: both;
Expand Down Expand Up @@ -10623,7 +10630,7 @@ div.video-preview video:first-child {
opacity: 1;
}
.configuration-switch {
width: 180px;
width: 200px;
padding: 10px;
}
.configuration-switch .well {
Expand Down
2 changes: 1 addition & 1 deletion public/css/kerberos.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/css/less/kerberos/settings/kios.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#kios-configuration
{
.tgl-ios:checked+.tgl-btn
{
background-color: #943633;
}
}
12 changes: 10 additions & 2 deletions public/css/less/kerberos/settings/main.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "timeselection";
@import "dropdown";
@import "toggle";

@import "kios";

#update-profile-modal
{
Expand All @@ -14,6 +14,14 @@
padding-right: 30px;
}

.switch-light
{
span span, a
{
outline: none !important;
}
}

#web-settings
{
.content
Expand Down Expand Up @@ -510,7 +518,7 @@

.configuration-switch
{
width: 180px;
width: 200px;
padding: 10px;

.well
Expand Down
16 changes: 16 additions & 0 deletions public/js/app/controllers/settings_kios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/********************************************
*
* KiOS Settings
*
**/

define(["jquery", "app/models/Settings", "app/views/SettingsKiOSView"], function($, Settings, SettingsKiOSView)
{
return {
initialize: function(autoremoval, forcenetwork, translations)
{
this.kios = new SettingsKiOSView(autoremoval, forcenetwork, translations);
this.kios.render();
}
};
});
50 changes: 50 additions & 0 deletions public/js/app/views/SettingsKiOSView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*********************
* KiOS settings view.
****/

define(["underscore", "backbone", "app/views/BaseView"],
function (_, Backbone, BaseView)
{
var SettingsKiOSView = BaseView.extend(
{
el : '#web-settings .kios-content',
view : 'settings-kios',

events:
{
"change #force-network": "updateToggle",
"change #auto-removal": "updateToggle",
},
initialize: function(autoremoval, forcenetwork, translations)
{
this.model = {};
this.model.autoremoval = autoremoval;
this.model.forcenetwork = forcenetwork;
this.model.translation = translations;
},
updateToggle: function(e)
{
var input = $(e.target);
var isChecked = input.is(':checked');

// We call the correct method in function
// of the id attribute of the toggle.
$.ajax({
url: _baseUrl + "/api/v1/" + input.attr('id'),
type: 'PUT',
data: {'active': isChecked},
success: function(data)
{
console.log(data);
}
});
},
render: function(model)
{
this.$el.html(this.template(this.model));
return this;
}
});

return SettingsKiOSView;
});
16 changes: 8 additions & 8 deletions public/js/app/views/SettingsWebView.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/********************************************************************
* Basic settings view: this is an easier view of the advanced view.
/*********************
* Web settings view.
****/

define(["underscore", "backbone", "app/views/BaseView", "seiyria-bootstrap-slider", "app/controllers/dashboard_heatmap"],
define(["underscore", "backbone", "app/views/BaseView", "seiyria-bootstrap-slider", "app/controllers/dashboard_heatmap"],
function (_, Backbone, BaseView, Slider, Heatmap)
{
{
var SettingsWebView = BaseView.extend(
{
el : '#web-settings .content',
el : '#web-settings .web-content',
view : 'settings-web',

events:
{
"change .slider-radius": "changeRadius",
Expand Down Expand Up @@ -48,7 +48,7 @@ define(["underscore", "backbone", "app/views/BaseView", "seiyria-bootstrap-slide
fps: "1",
radius: this.model.radius,
callback: function(){}
});
});

Heatmap.redraw();

Expand All @@ -59,4 +59,4 @@ define(["underscore", "backbone", "app/views/BaseView", "seiyria-bootstrap-slide
});

return SettingsWebView;
});
});
23 changes: 23 additions & 0 deletions public/js/mustache/settings-kios.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="with-tooltip element" style="clear: both; margin-bottom: 15px; display: table;">
<div class="button" style="float: left; margin-right: 20px;">
<input class="tgl tgl-ios" {{#forcenetwork}}checked{{/forcenetwork}} id="force-network" type="checkbox"/>
<label class="tgl-btn label-ios" data-tg-off="off" data-tg-on="on" for="force-network"></label>
</div>
<div style="float: left; margin-top: 2px;">Force network mode</div>
<span style="float: left; margin: 0; margin-top: -4px; margin-left: 10px;">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<span>{{translation.privacyInfo}}</span>
</span>
</div>

<div class="with-tooltip element" style="clear: both; margin-bottom: 15px; display: table;">
<div class="button" style="float: left; margin-right: 20px;">
<input class="tgl tgl-ios" {{#autoremoval}}checked{{/autoremoval}} id="auto-removal" type="checkbox"/>
<label class="tgl-btn label-ios" data-tg-off="off" data-tg-on="on" for="auto-removal"></label>
</div>
<div style="float: left; margin-top: 2px;">Auto removal media</div>
<span style="float: left; margin: 0; margin-top: -4px; margin-left: 10px;">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<span>{{translation.privacyInfo}}</span>
</span>
</div>
17 changes: 14 additions & 3 deletions resources/views/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@
</div>

<div id="web-settings" class="col-lg-6">
@if($kios)
<div id="kios-configuration">
<h2><i class="fa fa-server"></i> KiOS</h2>
<div class="kios-content content" style="margin-top: 30px; margin-bottom: 10px; display: table;">
<div id="loading-image-view" class="load4" style="padding:50px 0;">
<div class="loader"></div>
</div>
</div>
</div>
@endif
<div id="configuration">
<h2><i class="fa fa-eye"></i> Web</h2>
{{ Form::open(array('action' => 'SettingsController@updateWeb')) }}
<div class="content">
<div class="web-content content">
<div id="loading-image-view" class="load4" style="padding:50px 0;">
<div class="loader"></div>
</div>
Expand All @@ -57,11 +67,12 @@
{
require(["app/controllers/settings_advanced"], function(SettingsAdvanced){});
require(["app/controllers/toggleSettings", "app/controllers/settings_basic", "app/controllers/settings_web", "app/controllers/Cache"], function(toggleSettings, SettingsBasic, SettingsWeb, Cache)
require(["app/controllers/toggleSettings", "app/controllers/settings_basic", "app/controllers/settings_web", "app/controllers/settings_kios", "app/controllers/Cache"], function(toggleSettings, SettingsBasic, SettingsWeb, SettingsKiOS, Cache)
{
Cache(_baseUrl + "/api/v1/translate/settings").then(function (translation)
Cache(_baseUrl + "/api/v1/translate/settings").then(function(translation)
{
SettingsBasic.initialize(translation);
SettingsKiOS.initialize("{{$kios['autoremoval']}}", "{{$kios['forcenetwork']}}", translation);
SettingsWeb.initialize("{{$kerberos['radius']}}", translation);
});
Expand Down
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
Route::get('io/webhook', 'SettingsController@getIoWebhook');
Route::put('io/webhook', 'SettingsController@updateIoWebhook');

Route::put('force-network', 'SettingsController@updateForceNetwork');
Route::put('auto-removal', 'SettingsController@updateAutoRemoval');

Route::get('configure', array('uses' => 'SettingsController@getConfiguration'));
Route::put('configure', array('uses' => 'SettingsController@changeProperties'));

Expand Down

0 comments on commit bd891f6

Please sign in to comment.