Skip to content

Commit

Permalink
LIHADOOP-23924 Create dashboard of Dr Elephant using ember
Browse files Browse the repository at this point in the history
  • Loading branch information
nntnag17 committed Oct 18, 2016
1 parent 06a6b88 commit 58fb162
Show file tree
Hide file tree
Showing 98 changed files with 2,343 additions and 0 deletions.
13 changes: 13 additions & 0 deletions web/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import DS from 'ember-data';
import Ember from 'ember';

export default DS.JSONAPIAdapter.extend({
namespace: 'rest'
});

export default DS.RESTAdapter.extend({
namespace: 'rest',
pathForType: function (type) {
return Ember.String.pluralize(type);
}
});
18 changes: 18 additions & 0 deletions web/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Ember from 'ember';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;
4 changes: 4 additions & 0 deletions web/app/components/single-tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Component.extend({
});
22 changes: 22 additions & 0 deletions web/app/components/user-tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Ember from 'ember';

export default Ember.Component.extend({
newUser: null, // this is binded to the text box for adding user
showInputBox: false,
actions: {

/**
* sets showInputBox to true to show the input box
*/
showInput() {
this.set("showInputBox", true);
},

/**
* sets showInputBox to false to hide the input box
*/
resetInput() {
this.set("showInputBox", false);
}
}
});
6 changes: 6 additions & 0 deletions web/app/controllers/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Ember from 'ember';

export default Ember.Controller.extend({
queryParams: ['applicationid'],
applicationid: null,
});
34 changes: 34 additions & 0 deletions web/app/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Ember from 'ember';

export default Ember.Controller.extend({
showInputBox: false,
actions: {

/**
* This action adds a new tab and clicks on it once the tab is added and rendered
* @params user The user to be added as a tab
*/
addTab(user) {
this.users.addToUsername(user);
this.users.setActiveUser(user);
this.set('model.usernames',this.users.getUsernames());
Ember.run.scheduleOnce('afterRender', this, function() {
Ember.$("#"+user).trigger("click");
});
},

/**
* This action deletes the tab from the list and clicks on the `all` tab
* @params tabname the tab to delete
*/
deleteTab(tabname) {
this.users.deleteUsername(tabname);
this.set('model.usernames',this.users.getUsernames());
if(this.users.getActiveUser()===tabname) {
Ember.run.scheduleOnce('afterRender', this, function () {
Ember.$("#all a").trigger("click");
});
}
}
}
});
34 changes: 34 additions & 0 deletions web/app/controllers/dashboard/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import users from 'dr-elephant/models/users';
import Dashboard from 'dr-elephant/controllers/dashboard';

export default Dashboard.extend({
users: new users(),
loading: false,

/**
* This function returns the list of usernames currently stored
* @returns The list of usernames currently stored
*/
usernames() {
return this.users.getUsernames();
},

actions: {

/**
* changes the tab to the clicked user
* @params The name of the user tab
*/
changeTab(tabname) {
this.set("loading", true);
this.users.setActiveUser(tabname);
var _this = this;
_this.store.unloadAll();
var newApplications = this.store.query('application-summary', {username: tabname});
newApplications.then(function () {
_this.set("model.applications", newApplications);
_this.set("loading", false);
});
}
}
});
33 changes: 33 additions & 0 deletions web/app/controllers/dashboard/job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import users from 'dr-elephant/models/users';
import Dashboard from 'dr-elephant/controllers/dashboard';

export default Dashboard.extend({
users: new users(),
loading: false,

/**
* This function returns the list of usernames currently stored
* @returns The list of usernames currently stored
*/
usernames: function () {
return this.users.getUsernames();
},
actions: {

/**
* changes the tab to the clicked user
* @params The name of the user tab
*/
changeTab(tabname) {
this.set("loading", true);
this.users.setActiveUser(tabname);
var _this = this;
_this.store.unloadAll();
var newJobs = this.store.query('job-summary', {username: tabname});
newJobs.then(function () {
_this.set("model.jobs", newJobs);
_this.set("loading", false);
});
}
}
});
35 changes: 35 additions & 0 deletions web/app/controllers/dashboard/workflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Ember from 'ember';
import users from 'dr-elephant/models/users';
import Dashboard from 'dr-elephant/controllers/dashboard';

export default Dashboard.extend({
users: new users(),
loading: false,

/**
* This function returns the list of usernames currently stored
* @returns The list of usernames currently stored
*/
usernames: function () {
return this.users.getUsernames();
},
actions: {

/**
* changes the tab to the clicked user
* @params The name of the user tab
*/
changeTab(tabname) {
this.set("loading", true);
this.users.setActiveUser(tabname);
var _this = this;
_this.store.unloadAll();
var newworkflows = this.store.query('workflow-summary', {username: tabname});
newworkflows.then(function () {
_this.set("model.workflows", newworkflows);
_this.set("loading", false);
});
}

}
});
15 changes: 15 additions & 0 deletions web/app/helpers/eq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Ember from 'ember';

/**
* helper takes two parameters and returns true if both are equal else returns false
* @param params The parameters for the helper
* @returns {boolean}
*/
export function eq(params) {
if (params[0] === params[1]) {
return true;
}
return false;
}

export default Ember.Helper.helper(eq);
25 changes: 25 additions & 0 deletions web/app/helpers/get-bootstrap-severity-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Ember from 'ember';

/** Map to convert serverity to bootstrap class **/
const SEVERITY_TO_BOOTSTRAP_MAP = {
critical: "danger",
severe: "severe",
moderate: "warning",
low: "success",
none:"success"
};

/**
* This helper takes the serverity as the parameter value and returns the corresponding bootstrap code
* @param params The parameters
* @returns one of {"danger","severe","warning","success"}
*/
export function getBootstrapSeverityCode(params) {
let [severity] = params;
if (severity == null) {
return SEVERITY_TO_BOOTSTRAP_MAP.none;
}
return SEVERITY_TO_BOOTSTRAP_MAP[severity.toLowerCase()];
}

export default Ember.Helper.helper(getBootstrapSeverityCode);
26 changes: 26 additions & 0 deletions web/app/helpers/get-color-for-severity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ember from 'ember';


/** Map to convert severity to color **/
const SEVERITY_TO_COLOR_CODE_MAP = {
critical: "#D9534F",
severe: "#E4804E",
moderate: "#F0AD4E",
low: "#5CB85C",
none:"#5CB85C"
};

/**
* Returns the color based on the severity
* @param params The severity value
* @returns The color based on the serverity
*/
export function getColorForSeverity(params) {
let [severity] = params;
if(severity==null) {
return SEVERITY_TO_COLOR_CODE_MAP.none;
}
return SEVERITY_TO_COLOR_CODE_MAP[severity.toLowerCase()];
}

export default Ember.Helper.helper(getColorForSeverity);
13 changes: 13 additions & 0 deletions web/app/helpers/get-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';

/**
* Returns the date from milliseconds
* @param params The date to convert
* @returns The converted date
*/
export function getDate(params) {
let [date] = params;
return new Date(date);
}

export default Ember.Helper.helper(getDate);
29 changes: 29 additions & 0 deletions web/app/helpers/get-duration-breakdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Ember from 'ember';

const TIME = {
milliseconds_in_seconds: 1000,
seconds_in_minutes: 60,
minutes_in_hours: 60,
hours_in_days: 24
};

/**
* Breaks down milliseconds to HH:MM:SS
* @param params time in milliseconds
* @returns {*}
*/
export function getDurationBreakdown(params) {
let [duration] = params;
var seconds = parseInt((duration / TIME.milliseconds_in_seconds) % TIME.seconds_in_minutes), minutes = parseInt((duration / (TIME.milliseconds_in_seconds * TIME.seconds_in_minutes)) % TIME.minutes_in_hours), hours = parseInt((duration / (TIME.milliseconds_in_seconds * TIME.seconds_in_minutes * TIME.minutes_in_hours)) % TIME.hours_in_days);

if(duration<TIME.milliseconds_in_seconds) {
return "00:00:00";
}
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

return hours + ":" + minutes + ":" + seconds;
}

export default Ember.Helper.helper(getDurationBreakdown);
19 changes: 19 additions & 0 deletions web/app/helpers/get-percentage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Ember from 'ember';

/**
* Calculates the percentage given two params
* @param params The arguments for percentage
* @returns The percentage in the form PP.PP%
*/
export function getPercentage(params) {
let [arg1, arg2] = params;
if(arg2===0) {
return "0%";
}

var percentage = ( arg1 / arg2 ) * 100;
var percentString = percentage.toFixed(2).toString()+ "%";
return percentString;
}

export default Ember.Helper.helper(getPercentage);
29 changes: 29 additions & 0 deletions web/app/helpers/get-resource-in-gbhours.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Ember from 'ember';

const mbs_in_one_gb = 1024;
const seconds_in_one_hour = 3600;

/**
* Returns the resource after converting to GB Hours
* @param params The resource in MB Seconds
* @returns Resource in GB Hours
*/
export function getResourceInGBHours(params) {
let [MBSeconds] = params;
if (MBSeconds == 0) {
return "0 GB Hours";
}

var GBseconds = MBSeconds/mbs_in_one_gb;
var GBHours = GBseconds / seconds_in_one_hour;

if ((GBHours * 1000).toFixed(0) == 0) {
return "0 GB Hours";
}

var GBHoursString = GBHours.toFixed(3).toString();
GBHoursString = GBHoursString + " GB Hours";
return GBHoursString;
}

export default Ember.Helper.helper(getResourceInGBHours);
16 changes: 16 additions & 0 deletions web/app/helpers/not-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Ember from 'ember';

/**
* Checks if a given string is empty
* @param params
* @returns {boolean}
*/
export function notEmpty(params) {
let [id] = params;
if(id==="") {
return false;
}
return true;
}

export default Ember.Helper.helper(notEmpty);
Loading

0 comments on commit 58fb162

Please sign in to comment.