Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Close #192 - frame widget: refresh option (#205)
Browse files Browse the repository at this point in the history
Signed-off-by: Yannick Schaus <habpanel@schaus.net>
  • Loading branch information
ghys authored Jul 22, 2017
1 parent 04296d7 commit 661fea5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
6 changes: 6 additions & 0 deletions web/app/widgets/frame/frame.settings.tpl.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ <h3>iFrame Settings</h3>
<input type="url" name="frameUrl" ng-model="form.frameUrl" class="form-control">
</div>
</div>
<div class="form-group" ng-class="{error: _form.refresh.$error && _form.submitted}">
<label class="control-label col-lg-3 col-md-3">Refresh interval (seconds)</label>
<div class="col-lg-3 col-md-3">
<input name="refresh" type="number" ng-model="form.refresh" class="form-control" />
</div>
</div>
</div>
</div>
</uib-tab>
Expand Down
2 changes: 1 addition & 1 deletion web/app/widgets/frame/frame.tpl.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div ng-class="{ 'frame-content': !vm.widget.frameless, 'frame-content-frameless': vm.widget.frameless }">
<div class="frame-label" ng-hide="vm.widget.hidelabel">{{vm.widget.name}}</div>
<div class="frame-container">
<iframe width="100%" height="100%" name="{{vm.ngModel.name}}" ng-src="{{detailFrame}}" ng-style="{ 'background-color': vm.widget.background }" frameborder="0"> </iframe>
<iframe width="100%" height="100%" name="{{vm.ngModel.name}}" ng-src="{{vm.detailFrame}}" ng-style="{ 'background-color': vm.widget.background }" frameborder="0"> </iframe>
</div>
</div>
</div>
43 changes: 30 additions & 13 deletions web/app/widgets/frame/frame.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
});
});

widgetFrame.$inject = ['$rootScope', '$uibModal', 'OHService', '$sce'];
function widgetFrame($rootScope, $modal, OHService, $sce) {
widgetFrame.$inject = ['$rootScope', '$interval', 'OHService', '$sce'];
function widgetFrame($rootScope, $interval, OHService, $sce) {
// Usage: <widget-label ng-model="widget" />
//
// Creates: A label widget
Expand All @@ -35,30 +35,46 @@
return directive;

function link(scope, element, attrs) {
if (scope.vm.refreshInterval) {
element.on('$destroy', function () {
$interval.cancel(scope.vm.refreshInterval);
});
}
}
}

FrameController.$inject = ['$rootScope', '$scope', 'OHService', '$sce'];
function FrameController ($rootScope, $scope, OHService, $sce) {
FrameController.$inject = ['$rootScope', '$scope', '$interval', 'OHService', '$sce'];
function FrameController ($rootScope, $scope, $interval, OHService, $sce) {
var vm = this;
this.widget = this.ngModel;
vm.widget = this.ngModel;

function updateValue() {
var item = OHService.getItem(vm.widget.item);
if (!item || vm.widget.url_source !== 'item') {
vm.value = "";
return;
if (vm.widget.url_source === 'static') {
vm.value = vm.widget.frameUrl;
} else {
var item = OHService.getItem(vm.widget.item);
if (!item || vm.widget.url_source !== 'item') {
vm.value = "";
return;
}
vm.value = item.state;
}

if (vm.widget.refresh) {
vm.value += '?_t='+ (new Date()).getTime();
}
$scope.detailFrame = $sce.trustAsResourceUrl(item.state);

vm.detailFrame = $sce.trustAsResourceUrl(vm.value);
}

OHService.onUpdate($scope, vm.widget.item, function () {
updateValue();
});

if (this.widget.url_source === 'static') {
$scope.detailFrame = $sce.trustAsResourceUrl(this.widget.frameUrl);
if (vm.widget.refresh) {
vm.refreshInterval = $interval(updateValue, vm.widget.refresh * 1000);
}
updateValue();
};


Expand All @@ -80,7 +96,8 @@
frameUrl : widget.frameUrl,
frameless : widget.frameless,
hidelabel : widget.hidelabel,
background: widget.background
background: widget.background,
refresh : widget.refresh
};

$scope.dismiss = function() {
Expand Down

0 comments on commit 661fea5

Please sign in to comment.