This repository has been archived by the owner on Jan 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from NREL/website-backends
Add admin interface for managing website backend configurations
- Loading branch information
Showing
28 changed files
with
517 additions
and
90 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
41 changes: 41 additions & 0 deletions
41
app/assets/javascripts/admin/controllers/website_backends/form_controller.js
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,41 @@ | ||
Admin.WebsiteBackendsFormController = Ember.ObjectController.extend(Admin.Save, { | ||
backendProtocolOptions: [ | ||
{ id: 'http', name: 'http' }, | ||
{ id: 'https', name: 'https' }, | ||
], | ||
|
||
changeDefaultPort: function() { | ||
var protocol = this.get('model.backendProtocol'); | ||
var port = parseInt(this.get('model.serverPort'), 10); | ||
if(protocol === 'https') { | ||
if(!port || port === 80) { | ||
this.set('model.serverPort', 443); | ||
} | ||
} else { | ||
if(!port || port === 443) { | ||
this.set('model.serverPort', 80); | ||
} | ||
} | ||
}.observes('model.backendProtocol'), | ||
|
||
actions: { | ||
submit: function() { | ||
this.save({ | ||
transitionToRoute: 'website_backends', | ||
message: 'Successfully saved the "' + this.get('model.frontendHost') + '" website backend<br><strong>Note:</strong> Your changes are not yet live. <a href="/admin/#/config/publish">Publish Changes</a> to send your updates live.', | ||
}); | ||
}, | ||
|
||
delete: function() { | ||
bootbox.confirm('Are you sure you want to delete this website backend?', _.bind(function(result) { | ||
if(result) { | ||
this.get('model').deleteRecord(); | ||
this.transitionToRoute('website_backends'); | ||
} | ||
}, this)); | ||
}, | ||
}, | ||
}); | ||
|
||
Admin.WebsiteBackendsEditController = Admin.WebsiteBackendsFormController.extend(); | ||
Admin.WebsiteBackendsNewController = Admin.WebsiteBackendsFormController.extend(); |
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,38 @@ | ||
Admin.WebsiteBackend = Ember.Model.extend(Ember.Validations.Mixin, { | ||
id: Ember.attr(), | ||
frontendHost: Ember.attr(), | ||
backendProtocol: Ember.attr(), | ||
serverHost: Ember.attr(), | ||
serverPort: Ember.attr(Number), | ||
|
||
validations: { | ||
frontendHost: { | ||
presence: true, | ||
format: { | ||
with: CommonValidations.frontend_host_format, | ||
message: polyglot.t('errors.messages.invalid_host_format'), | ||
}, | ||
}, | ||
backendProtocol: { | ||
presence: true, | ||
}, | ||
serverHost: { | ||
presence: true, | ||
format: { | ||
with: CommonValidations.frontend_host_format, | ||
message: polyglot.t('errors.messages.invalid_host_format'), | ||
}, | ||
}, | ||
serverPort: { | ||
presence: true, | ||
numericality: true, | ||
}, | ||
}, | ||
}); | ||
|
||
Admin.WebsiteBackend.url = '/api-umbrella/v1/website_backends'; | ||
Admin.WebsiteBackend.rootKey = 'website_backend'; | ||
Admin.WebsiteBackend.collectionKey = 'data'; | ||
Admin.WebsiteBackend.primaryKey = 'id'; | ||
Admin.WebsiteBackend.camelizeKeys = true; | ||
Admin.WebsiteBackend.adapter = Admin.APIUmbrellaRESTAdapter.create(); |
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
8 changes: 8 additions & 0 deletions
8
app/assets/javascripts/admin/routes/website_backends/base_route.js
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,8 @@ | ||
Admin.WebsiteBackendsBaseRoute = Ember.Route.extend({ | ||
setupController: function(controller, model) { | ||
controller.set('model', model); | ||
|
||
$('ul.nav li').removeClass('active'); | ||
$('ul.nav li.nav-config').addClass('active'); | ||
}, | ||
}); |
10 changes: 10 additions & 0 deletions
10
app/assets/javascripts/admin/routes/website_backends/edit_route.js
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,10 @@ | ||
Admin.WebsiteBackendsEditRoute = Admin.WebsiteBackendsBaseRoute.extend({ | ||
model: function(params) { | ||
// Clear the record cache, so this is always fetched from the server (to | ||
// account for two users simultaneously editing the same record). | ||
Admin.WebsiteBackend.clearCache(); | ||
|
||
return Admin.WebsiteBackend.find(params.websiteBackendId); | ||
}, | ||
}); | ||
|
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/admin/routes/website_backends/index_route.js
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,2 @@ | ||
Admin.WebsiteBackendsIndexRoute = Admin.WebsiteBackendsBaseRoute.extend({ | ||
}); |
8 changes: 8 additions & 0 deletions
8
app/assets/javascripts/admin/routes/website_backends/new_route.js
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,8 @@ | ||
Admin.WebsiteBackendsNewRoute = Admin.WebsiteBackendsBaseRoute.extend({ | ||
model: function() { | ||
return Admin.WebsiteBackend.create({ | ||
serverPort: 80, | ||
}); | ||
}, | ||
}); | ||
|
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
38 changes: 38 additions & 0 deletions
38
app/assets/javascripts/admin/templates/website_backends/_form.hbs
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,38 @@ | ||
{{error-messages model=model}} | ||
|
||
{{#form-for model}} | ||
<fieldset class="form-horizontal info"> | ||
{{input frontendHost | ||
label='Frontend Host' | ||
placeholder='example.com' | ||
inputConfig='class:span6'}} | ||
|
||
{{input backendProtocol as='select' | ||
label=(t 'mongoid.attributes.api.backend_protocol') | ||
value='backendProtocol' | ||
collection='backendProtocolOptions' | ||
optionValuePath='content.id' | ||
optionLabelPath='content.name'}} | ||
|
||
{{input serverHost | ||
label='Backend Server' | ||
placeholder='example.github.io' | ||
inputConfig='class:span6'}} | ||
|
||
{{input serverPort | ||
label='Backend Port' | ||
inputConfig='class:span2'}} | ||
</fieldset> | ||
|
||
<div class="row-fluid"> | ||
<div class="span6"> | ||
<button type="submit" id="save_button" class="btn btn-large btn-primary" data-loading-text="<i class='fa fa-refresh fa-spin'></i> Saving...">Save</button> | ||
</div> | ||
<div class="span6 record-details"> | ||
{{#if id}} | ||
Created: {{formatDate createdAt}} by {{creator.username}}<br> | ||
Last Updated: {{formatDate updatedAt}} by {{updater.username}}<br> | ||
{{/if}} | ||
</div> | ||
</div> | ||
{{/form-for}} |
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/admin/templates/website_backends/edit.hbs
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,2 @@ | ||
<h1>Edit Website Backend</h1> | ||
{{partial "website_backends/form"}} |
9 changes: 9 additions & 0 deletions
9
app/assets/javascripts/admin/templates/website_backends/index.hbs
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,9 @@ | ||
<h1>Website Backends</h1> | ||
|
||
<div class="button-actions button-actions-down"> | ||
<a href="#/website_backends/new" class="btn btn-primary"><i class="fa fa-plus"></i> Add Website Backend</a> | ||
</div> | ||
|
||
<div id="results_table searchable-table-with-add"> | ||
{{view Admin.WebsiteBackendsTableView}} | ||
</div> |
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/admin/templates/website_backends/new.hbs
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,2 @@ | ||
<h1>Add Website Backend</h1> | ||
{{partial "website_backends/form"}} |
7 changes: 0 additions & 7 deletions
7
app/assets/javascripts/admin/views/config/publish_api_view.js
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
app/assets/javascripts/admin/views/config/publish_record_view.js
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,7 @@ | ||
Admin.ConfigPublishRecordView = Ember.View.extend({ | ||
actions: { | ||
toggleConfigDiff: function(id) { | ||
$('[data-diff-id=' + id + ']').toggle(); | ||
} | ||
} | ||
}); |
31 changes: 31 additions & 0 deletions
31
app/assets/javascripts/admin/views/website_backends/table_view.js
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,31 @@ | ||
Admin.WebsiteBackendsTableView = Ember.View.extend({ | ||
tagName: 'table', | ||
classNames: ['table', 'table-striped', 'table-bordered', 'table-condensed'], | ||
|
||
didInsertElement: function() { | ||
this.set('table', this.$().DataTable({ | ||
serverSide: true, | ||
ajax: '/api-umbrella/v1/website_backends.json', | ||
pageLength: 50, | ||
rowCallback: function(row, data) { | ||
$(row).data('id', data.id); | ||
}, | ||
order: [[0, 'asc']], | ||
columns: [ | ||
{ | ||
data: 'frontend_host', | ||
title: 'Host', | ||
defaultContent: '-', | ||
render: _.bind(function(name, type, data) { | ||
if(type === 'display' && name && name !== '-') { | ||
var link = '#/website_backends/' + data.id + '/edit'; | ||
return '<a href="' + link + '">' + _.escape(name) + '</a>'; | ||
} | ||
|
||
return name; | ||
}, this), | ||
}, | ||
] | ||
})); | ||
}, | ||
}); |
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
Oops, something went wrong.