Skip to content

Commit

Permalink
Merge pull request #423 from piotr-cz/master-gmaps-key
Browse files Browse the repository at this point in the history
Option to set google masp API key (Cockpit-Master)
  • Loading branch information
aheinze committed Jul 21, 2016
2 parents 247b5df + c90cd6f commit 186a5d6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
14 changes: 9 additions & 5 deletions assets/js/angular/fields/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

(function($){

angular.module('cockpit.fields').directive("locationfield", ['$timeout', '$compile', function($timeout, $compile){

angular.module('cockpit.fields').directive("locationfield", ['$timeout', '$compile', '$http', function($timeout, $compile, $http) {

var uuid = 0,
locale = document.documentElement.lang.toUpperCase(),
Expand All @@ -23,9 +22,14 @@

script.onload = function() {

google.load('maps', '3', {other_params: 'sensor=false&libraries=places&language=' + locale, callback: function(){
if (google && google.maps.places) resolve();
}});
$http
.post(App.route('/settings/getGmapsKey'))
.success(function(key) {

google.load('maps', '3', {other_params: 'key=' + key + '&libraries=places&language=' + locale, callback: function() {
if (google && google.maps.places) resolve();
}});
});
};

script.onerror = function() {
Expand Down
17 changes: 16 additions & 1 deletion modules/core/Cockpit/Controller/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ public function general() {
$registry = json_encode((object)$this->app->memory->get("cockpit.api.registry", []));
$tokens = $this->app->db->getKey("cockpit/settings", "cockpit.api.tokens", null);
$locales = json_encode($this->app->db->getKey("cockpit/settings", "cockpit.locales", []));
$gmapskey = $this->app->db->getKey("cockpit/settings", "cockpit.gmaps.key", '');

if (!$tokens) {
$tokens = new \stdClass;
}

return $this->render('cockpit:views/settings/general.php', compact('tokens', 'registry', 'locales'));
return $this->render('cockpit:views/settings/general.php', compact('tokens', 'registry', 'locales', 'gmapskey'));
}

public function info() {
Expand Down Expand Up @@ -138,4 +139,18 @@ public function saveLocals() {

return ["success"=>true];
}

public function getGmapsKey() {

return $this->app->db->getKey("cockpit/settings", "cockpit.gmaps.key", '');
}

public function saveGmapsKey() {

$gmapskey = $this->param("key", "");

$this->app->db->setKey("cockpit/settings", "cockpit.gmaps.key", (string) $gmapskey);

return ["success" => true];
}
}
18 changes: 18 additions & 0 deletions modules/core/Cockpit/views/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<li><a href="#LOCALES">@lang('Locales')</a></li>
<li><a href="#REGISTRY">@lang('Registry')</a></li>
<li><a href="#SYSTEM">@lang('API')</a></li>
<li><a href="#GMAPS">@lang('Google Maps')</a></li>
</ul>
</div>
Expand Down Expand Up @@ -168,7 +169,17 @@
<button class="uk-button uk-button-large" ng-click="generateToken()">@lang('Generate api token')</button>
</div>
<div>
<span class="uk-badge app-badge">@lang('Google Maps')</span>
<hr />
<div class="uk-margin uk-form">
<label class="uk-text-small">@lang('Google Maps API Key')</label>
<input type="text" class="uk-form-large uk-width-1-1" ng-model="gmapskey" />
</div>
<button class="uk-button uk-button-large" type="button" ng-click="saveGmapsKey()">@lang('Save')</button>
</div>
</div>
</div>
</div>
Expand All @@ -182,6 +193,7 @@
$scope.tokens = {{ json_encode($tokens) }};
$scope.registry = {{ $registry }};
$scope.locales = {{ $locales }};
$scope.gmapskey = '{{ $gmapskey }}';
$scope.languages = {};
Expand Down Expand Up @@ -295,6 +307,12 @@
}).error(App.module.callbacks.error.http);
};
$scope.saveGmapsKey = function() {
$http.post(App.route("/settings/saveGmapsKey"), {"key": $scope.gmapskey}).success(function(data) {
App.notify("@lang('Key updated!')", "success");
}).error(App.module.callbacks.error.http);
};
function buildToken(bits, base) {
if (!base) base = 16;
if (bits === undefined) bits = 128;
Expand Down

0 comments on commit 186a5d6

Please sign in to comment.