Skip to content

Commit

Permalink
recovered networks with new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Ruiz committed Mar 6, 2019
1 parent a64bad4 commit 3f895b0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 41 deletions.
23 changes: 23 additions & 0 deletions js/camera/CameraInteractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@

Object.defineProperties(CameraInteractor.prototype,
{
getCamera : {
value: function(networkId, cameraId, listener)
{
$.ajax
({
type: "GET",
url: "https://rest-" + credentials.region + "." + server + "/network/" + networkId + "/camera/" + cameraId,
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader("TOKEN_AUTH", credentials.token);
},
success: function (data)
{
listener.onSuccess(data);
},
error: function (jqxhr, textStatus, error)
{
listener.onError(error);
}
});
},
enumerable: false
},
getThumbnail : {
value: function(path, listener)
{
Expand Down
22 changes: 20 additions & 2 deletions js/camera/CameraPresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,33 @@

Object.defineProperties(CameraPresenter.prototype,
{
getCamera : {
value: function(networkId, cameraId, cameraName)
{
var self = this;

this.interactor.getCamera(networkId, cameraId, new blink.listeners.BaseDecisionListener(
function(data)
{
data.camera_status.name = cameraName;
self.cameraView.onCamera(data);
},
function(data)
{
self.cameraView.showError(data);
}));
},
enumerable: false
},
getThumbnail : {
value: function(path)
value: function(path, onSuccess)
{
var self = this;

this.interactor.getThumbnail(path, new blink.listeners.BaseDecisionListener(
function(data)
{
self.cameraView.onThumbnail(data);
onSuccess(data);
},
function(data)
{
Expand Down
57 changes: 35 additions & 22 deletions js/camera/CameraView.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(function(views)
{
var self;
var card;

function CameraView(presenter)
{
Expand All @@ -21,9 +20,7 @@
load : {
value: function(data)
{
console.log(data)

this.card = $("<div/>", {class: "demo-card-square mdl-card mdl-shadow--2dp"});
var card = $("<div/>", {class: "demo-card-square mdl-card mdl-shadow--2dp"});

var icons = "";

Expand All @@ -45,36 +42,52 @@

var description = data.temperature + " ºF - Updated ";

if(data.enabled)
{
description += moment(data.updated_at).fromNow();
}
else
{
description += "<span class='error'>Disabled</span>";
}

description += moment(data.updated_at).fromNow();

var content = "<div class='description'>" + description + "</div><div class='icons'>" + icons + "</div>";

var title = $("<div/>", {class: "mdl-card__title mdl-card--expand", html: "<h2 class='mdl-card__title-text'>" + data.name + "</h2>"});
var serial = " (" + data.serial + ")";

var title = $("<div/>", {class: "mdl-card__title mdl-card--expand", html: "<h2 class='mdl-card__title-text'>" + data.name + serial + "</h2>"});
var text = $("<div/>", {class: "mdl-card__supporting-text", html: content});
var actions = $("<div/>", {class: "mdl-card__actions mdl-card--border", html: "<a class='mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect'>View Events</a>"});

title.appendTo(this.card);
text.appendTo(this.card);
actions.appendTo(this.card);
title.appendTo(card);
text.appendTo(card);
actions.appendTo(card);

this.card.appendTo($(".content"));
this.presenter.getThumbnail(data.thumbnail, function(data2)
{
var image = card.find(".mdl-card__title");
image.css("background-image", "url('data:image/png;base64," + data2 + "')");
});

this.presenter.getThumbnail(data.thumbnail);
card.appendTo($(".content"));
},
enumerable: false
},
onNetwork : {
value: function(data)
{
$("#network" + data.network_id).click(function(evt)
{
$(".header > div > span").html($(this).data("name"));
$(".content").html("");

$.each( data.cameras, function( key, value2 )
{
self.presenter.getCamera(data.network_id, value2.id, value2.name);
});

evt.preventDefault();
});
},
enumerable: false
},
onThumbnail : {
onCamera : {
value: function(data)
{
var image = this.card.find(".mdl-card__title");
image.css("background-image", "url('data:image/png;base64," + data + "')");
self.load(data.camera_status);
},
enumerable: false
},
Expand Down
2 changes: 1 addition & 1 deletion js/network/NetworkInteractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$.ajax
({
type: "GET",
url: "https://rest-" + credentials.region + "." + server + "/networks/",
url: "https://rest-" + credentials.region + "." + server + "/api/v1/camera/usage",
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader("TOKEN_AUTH", credentials.token);
Expand Down
9 changes: 4 additions & 5 deletions js/network/NetworkPresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
function(data)
{
self.networkView.onNetworks(data);
$.each( data.networks, function( key, value )
{
self.ctx.getCameraPresenter().cameraView.onNetwork(value);
});
},
function(data)
{
Expand All @@ -40,11 +44,6 @@
function(data)
{
self.networkView.onNetwork(data);

$.each( data.devicestatus, function( key, value )
{
self.ctx.getCameraPresenter().cameraView.load(value);
});
},
function(data)
{
Expand Down
17 changes: 6 additions & 11 deletions js/network/NetworkView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
var self = this;

$(".drawer .navigation").append("<div class='separator'>Networks</div>");
//$(".drawer .navigation").append("<div class='mdl-layout-spacer'></div>");
$.each( data.networks, function( key, value )
{
var network = $("<a/>", {class: "mdl-navigation__link", href: "#", "data-name": value.name, "data-id": value.id, html: "<i class='fas fa-network-wired'></i>" + value.name});

network.click(function(evt)
{
$(".header > div > span").html($(this).data("name"));

self.presenter.getNetwork($(this).data("id"));
evt.preventDefault();
});

var network = $("<a/>", {class: "mdl-navigation__link",
id: "network" + value.network_id,
href: "#", "data-name": value.name,
"data-id": value.network_id,
html: "<i class='fas fa-network-wired'></i>" + value.name});

network.appendTo($(".drawer .navigation"));
});
},
Expand Down

0 comments on commit 3f895b0

Please sign in to comment.