Merge pull request #90 from Dahlgren/feature/marionette-2

Update frontend dependencies
This commit is contained in:
Björn Dahlgren 2018-08-18 02:58:02 +02:00 committed by GitHub
commit 09c44ef585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 78 additions and 80 deletions

View File

@ -14,11 +14,13 @@ define(function (require) {
Logs = require('app/collections/logs'), Logs = require('app/collections/logs'),
Missions = require('app/collections/missions'), Missions = require('app/collections/missions'),
Mods = require('app/collections/mods'), Mods = require('app/collections/mods'),
Settings = require('app/models/settings'),
Servers = require('app/collections/servers'), Servers = require('app/collections/servers'),
$body = $('body'), $body = $('body'),
missions = new Missions(), missions = new Missions(),
mods = new Mods(), mods = new Mods(),
settings = new Settings(),
servers = new Servers(), servers = new Servers(),
layoutView = new LayoutView({el: $body}).render(); layoutView = new LayoutView({el: $body}).render();
@ -33,18 +35,19 @@ define(function (require) {
}, },
initialize: function () { initialize: function () {
layoutView.navigation.show(new NavigationView({servers: servers})); layoutView.navigation.show(new NavigationView({settings: settings, servers: servers}));
sweetAlertInitialize(); sweetAlertInitialize();
missions.fetch(); missions.fetch();
settings.fetch();
var initialized = false; var initialized = false;
var socket = io.connect(); var socket = io.connect();
socket.on('mods', function (_mods) { socket.on('mods', function (_mods) {
mods.set(_mods).sort(); mods.set(_mods);
}); });
socket.on('servers', function (_servers) { socket.on('servers', function (_servers) {
servers.set(_servers).sort(); servers.set(_servers);
if (!initialized) { if (!initialized) {
initialized = true; initialized = true;

View File

@ -8,7 +8,7 @@ define(function (require) {
Marionette = require('marionette'), Marionette = require('marionette'),
tpl = require('text!tpl/layout.html'); tpl = require('text!tpl/layout.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {

View File

@ -12,8 +12,8 @@ define(function (require) {
template = _.template(tpl); template = _.template(tpl);
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: template, template: template,
}); });
}); });

View File

@ -16,10 +16,10 @@ define(function (require) {
template: template, template: template,
events: { events: {
"click .destroy": "destroy", "click .destroy": "deleteLog",
}, },
destroy: function (event) { deleteLog: function (event) {
var self = this; var self = this;
sweetAlert({ sweetAlert({
title: "Are you sure?", title: "Are you sure?",

View File

@ -11,7 +11,7 @@ define(function (require) {
ListView = require('app/views/missions/list'), ListView = require('app/views/missions/list'),
tpl = require('text!tpl/missions/index.html'); tpl = require('text!tpl/missions/index.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {

View File

@ -12,12 +12,8 @@ define(function (require) {
template = _.template(tpl); template = _.template(tpl);
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: template, template: template,
initialize: function (options) {
this.listenTo(this.collection, "change reset", this.render);
},
}); });
}); });

View File

@ -16,10 +16,10 @@ define(function (require) {
template: template, template: template,
events: { events: {
"click .delete": "delete" "click .delete": "deleteMission"
}, },
delete: function (event) { deleteMission: function (event) {
var self = this; var self = this;
sweetAlert({ sweetAlert({
title: "Are you sure?", title: "Are you sure?",

View File

@ -20,7 +20,6 @@ define(function (require) {
initialize: function (options) { initialize: function (options) {
this.missions = options.missions; this.missions = options.missions;
this.model = new Mission();
}, },
submit: function () { submit: function () {

View File

@ -12,18 +12,14 @@ define(function (require) {
template = _.template(tpl); template = _.template(tpl);
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: template, template: template,
events: { events: {
"click #refresh": "refresh", "click #refresh": "refresh",
}, },
initialize: function (options) {
this.listenTo(this.collection, "change reset", this.render);
},
refresh: function (event) { refresh: function (event) {
event.preventDefault(); event.preventDefault();
$.ajax({ $.ajax({

View File

@ -17,10 +17,10 @@ define(function (require) {
template: template, template: template,
events: { events: {
"click .destroy": "destroy", "click .destroy": "deleteMod",
}, },
destroy: function (event) { deleteMod: function (event) {
var self = this; var self = this;
sweetAlert({ sweetAlert({
title: "Are you sure?", title: "Are you sure?",

View File

@ -19,6 +19,7 @@ define(function (require) {
}, },
initialize: function (options) { initialize: function (options) {
this.settings = options.settings;
this.servers = options.servers; this.servers = options.servers;
this.serversListView = new ServersListView({ collection: this.servers }) this.serversListView = new ServersListView({ collection: this.servers })
}, },
@ -30,7 +31,7 @@ define(function (require) {
settings: function (event) { settings: function (event) {
event.preventDefault(); event.preventDefault();
var view = new SettingsView(); var view = new SettingsView({ model: this.settings });
new Backbone.BootstrapModal({ content: view, animate: true, cancelText: false }).open(); new Backbone.BootstrapModal({ content: view, animate: true, cancelText: false }).open();
} }
}); });

View File

@ -10,6 +10,6 @@ define(function (require) {
return Marionette.CollectionView.extend({ return Marionette.CollectionView.extend({
tagName: 'ul', tagName: 'ul',
itemView: ListItemView, childView: ListItemView,
}); });
}); });

View File

@ -9,7 +9,7 @@ define(function (require) {
swal = require('sweet-alert'), swal = require('sweet-alert'),
tpl = require('text!tpl/servers/info.html'); tpl = require('text!tpl/servers/info.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
events: { events: {

View File

@ -15,8 +15,8 @@ define(function (require) {
template = _.template(tpl); template = _.template(tpl);
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: template, template: template,
emptyView: EmptyView, emptyView: EmptyView,
@ -25,20 +25,16 @@ define(function (require) {
"click #add-server": "addServer" "click #add-server": "addServer"
}, },
initialize: function (options) { buildChildView: function(item, ChildViewType, childViewOptions){
this.listenTo(this.collection, "change reset", this.render);
},
buildItemView: function(item, ItemViewType, itemViewOptions){
// build the final list of options for the item view type // build the final list of options for the item view type
var options = _.extend({model: item}, itemViewOptions); var options = _.extend({model: item}, childViewOptions);
if (ItemViewType == EmptyView) { if (ChildViewType == EmptyView) {
options = _.extend({servers: this.collection}, options); options = _.extend({servers: this.collection}, options);
} }
// create the item view instance // create the item view instance
var view = new ItemViewType(options); var view = new ChildViewType(options);
// return it // return it
return view; return view;
}, },

View File

@ -10,14 +10,14 @@ define(function (require) {
tpl = require('text!tpl/servers/missions/available/list.html'); tpl = require('text!tpl/servers/missions/available/list.html');
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: _.template(tpl), template: _.template(tpl),
buildItemView: function(item, ItemViewType, itemViewOptions){ buildChildView: function(item, ChildViewType, childViewOptions){
var self = this; var self = this;
var options = _.extend({model: item}, itemViewOptions); var options = _.extend({model: item}, childViewOptions);
var view = new ItemViewType(options); var view = new ChildViewType(options);
view.on('add', function (model) { view.on('add', function (model) {
self.trigger('add', model); self.trigger('add', model);
}); });

View File

@ -11,7 +11,7 @@ define(function (require) {
RotationListView = require('app/views/servers/missions/rotation/list'), RotationListView = require('app/views/servers/missions/rotation/list'),
tpl = require('text!tpl/servers/missions/index.html'); tpl = require('text!tpl/servers/missions/index.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {
@ -25,7 +25,6 @@ define(function (require) {
initialize: function (options) { initialize: function (options) {
this.missions = options.missions; this.missions = options.missions;
this.model = options.server;
this.rotationCollection = new MissionRotations(this.model.get('missions')); this.rotationCollection = new MissionRotations(this.model.get('missions'));

View File

@ -11,8 +11,8 @@ define(function (require) {
tpl = require('text!tpl/servers/missions/rotation/list.html'); tpl = require('text!tpl/servers/missions/rotation/list.html');
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: _.template(tpl), template: _.template(tpl),
events: { events: {

View File

@ -12,7 +12,7 @@ define(function (require) {
tpl = require('text!tpl/servers/mods/list.html'); tpl = require('text!tpl/servers/mods/list.html');
return ModsListView.extend({ return ModsListView.extend({
itemView: ListItemView, childView: ListItemView,
template: _.template(tpl), template: _.template(tpl),
events: { events: {
@ -20,9 +20,9 @@ define(function (require) {
"click .uncheck-all": "uncheckAll", "click .uncheck-all": "uncheckAll",
}, },
buildItemView: function(item, ItemViewType, itemViewOptions){ buildChildView: function(item, ChildViewType, childViewOptions){
var options = _.extend({model: item, server: this.options.server}, itemViewOptions); var options = _.extend({model: item, server: this.options.server}, childViewOptions);
var view = new ItemViewType(options); var view = new ChildViewType(options);
return view; return view;
}, },

View File

@ -12,22 +12,21 @@ define(function (require) {
tpl = require('text!tpl/servers/parameters/list.html'); tpl = require('text!tpl/servers/parameters/list.html');
return Marionette.CompositeView.extend({ return Marionette.CompositeView.extend({
itemView: ListItemView, childView: ListItemView,
itemViewContainer: "tbody", childViewContainer: "tbody",
template: _.template(tpl), template: _.template(tpl),
events: { events: {
"click .add-parameter": "addParameter", "click .add-parameter": "addParameter",
}, },
initialize: function (options) { modelEvents: {
this.model = options.server; "change": "serverUpdated",
},
this.collection = new Parameters(this.model.get('parameters').map(function (parameter) { initialize: function (options) {
return new Parameter({ this.collection = new Parameters();
parameter: parameter, this.serverUpdated();
});
}));
}, },
addParameter: function (e) { addParameter: function (e) {
@ -42,6 +41,14 @@ define(function (require) {
}), }),
}; };
}, },
serverUpdated: function () {
this.collection.reset(this.model.get('parameters').map(function (parameter) {
return new Parameter({
parameter: parameter,
});
}));
},
}); });
}); });

View File

@ -8,7 +8,7 @@ define(function (require) {
Marionette = require('marionette'), Marionette = require('marionette'),
tpl = require('text!tpl/servers/players.html'); tpl = require('text!tpl/servers/players.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
templateHelpers: { templateHelpers: {
players: function(){ players: function(){

View File

@ -15,7 +15,7 @@ define(function (require) {
PlayersView = require('app/views/servers/players'), PlayersView = require('app/views/servers/players'),
tpl = require('text!tpl/servers/view.html'); tpl = require('text!tpl/servers/view.html');
return Marionette.Layout.extend({ return Marionette.LayoutView.extend({
template: _.template(tpl), template: _.template(tpl),
regions: { regions: {
@ -43,9 +43,9 @@ define(function (require) {
onRender: function() { onRender: function() {
this.infoView.show(new InfoView({model: this.model})); this.infoView.show(new InfoView({model: this.model}));
this.missionsView.show(new MissionsView({missions: this.missions, server: this.model})); this.missionsView.show(new MissionsView({missions: this.missions, model: this.model}));
this.modsView.show(new ModsListView({collection: this.mods, server: this.model})); this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
this.parametersView.show(new ParametersListView({server: this.model})); this.parametersView.show(new ParametersListView({model: this.model}));
this.playersView.show(new PlayersView({model: this.model})); this.playersView.show(new PlayersView({model: this.model}));
this.settingsView.show(new FormView({model: this.model})); this.settingsView.show(new FormView({model: this.model}));
}, },

View File

@ -6,7 +6,6 @@ define(function (require) {
_ = require('underscore'), _ = require('underscore'),
Backbone = require('backbone'), Backbone = require('backbone'),
Marionette = require('marionette'), Marionette = require('marionette'),
Settings = require('app/models/settings'),
tpl = require('text!tpl/settings.html'); tpl = require('text!tpl/settings.html');
return Marionette.ItemView.extend({ return Marionette.ItemView.extend({
@ -16,11 +15,6 @@ define(function (require) {
'change': 'render', 'change': 'render',
}, },
initialize: function () {
this.model = new Settings()
this.model.fetch();
},
templateHelpers: { templateHelpers: {
isTypeChecked: function(type) { isTypeChecked: function(type) {
return this.type === type ? 'checked' : ''; return this.type === type ? 'checked' : '';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long