Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Middleware handling | ||
* | ||
* @author Andreas Götz <cpuidle@gmx.de> | ||
* @copyright Copyright (c) 2017, The volkszaehler.org project | ||
* @package default | ||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License | ||
*/ | ||
/* | ||
* This file is part of volkzaehler.org | ||
* | ||
* volkzaehler.org is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or any later version. | ||
* | ||
* volkzaehler.org is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* volkszaehler.org. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* Middleware constructor | ||
* @var middleware definition | ||
*/ | ||
var Middleware = function(definition) { | ||
this.title = definition.title; | ||
this.url = definition.url; | ||
this.live = definition.live || null; | ||
|
||
this.public = []; | ||
this.session = null; | ||
}; | ||
|
||
/** | ||
* Load public entities | ||
*/ | ||
Middleware.prototype.loadEntities = function() { | ||
return vz.load({ | ||
controller: 'entity', | ||
url: this.url, | ||
context: this | ||
}).then(function(json) { | ||
this.public = []; | ||
|
||
json.entities.forEach(function(json) { | ||
var entity = new Entity(json, this.url); | ||
this.public.push(entity); | ||
}, this); | ||
this.public.sort(Entity.compare); | ||
|
||
// chainable | ||
return this; | ||
}); | ||
}; | ||
|
||
/** | ||
* Find middleware by url | ||
*/ | ||
vz.middleware.find = function(url) { | ||
var mw = $.grep(vz.middleware, function(middleware) { | ||
if (url == middleware.url) { | ||
return true; | ||
} | ||
}); | ||
|
||
return mw.length ? mw[0] : null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters