-
-
Notifications
You must be signed in to change notification settings - Fork 87
Hide and show columns, allow for zero to 3 columns, query param for numColumns #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56f62d3
95125f2
9bddcb8
cb7aefc
51df25f
c09ccad
1c7d491
5576520
7ffff31
19bcb76
e736445
aff7cdd
81002ea
dffa415
9bd6dbf
6efa51c
4e96640
47072aa
d74b36b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,25 @@ import Ember from "ember"; | |
| import config from '../config/environment'; | ||
| import Settings from '../models/settings'; | ||
| import ErrorMessages from 'ember-twiddle/helpers/error-messages'; | ||
| import Column from '../utils/column'; | ||
|
|
||
| const { | ||
| computed: { equal }, | ||
| observer, | ||
| computed, | ||
| run | ||
| } = Ember; | ||
|
|
||
| const MAX_COLUMNS = 3; | ||
|
|
||
| export default Ember.Controller.extend({ | ||
| emberCli: Ember.inject.service('ember-cli'), | ||
| version: config.APP.version, | ||
|
|
||
| queryParams: ['numColumns'], | ||
| numColumns: 2, | ||
|
|
||
| init() { | ||
| this._super(...arguments); | ||
| this.createColumns(); | ||
| this.setupWindowUpdate(); | ||
| }, | ||
|
|
||
|
|
@@ -22,14 +29,32 @@ export default Ember.Controller.extend({ | |
| * @type {String} | ||
| */ | ||
| buildOutput: '', | ||
|
|
||
| /** | ||
| * If the code is currently being built | ||
| * @type {boolean} | ||
| */ | ||
| isBuilding: false, | ||
|
|
||
| /** | ||
| * If the edited code has not been saved by the user | ||
| * @type {boolean} | ||
| */ | ||
| unsaved: true, | ||
|
|
||
| /** | ||
| * File in the current active editor column | ||
| * @type {Object} | ||
| */ | ||
| activeFile: null, | ||
|
|
||
| /** | ||
| * Column which has the currently focused editor | ||
| * @type {Number} | ||
| */ | ||
| activeEditorCol: null, | ||
| col1File: null, | ||
| col2File: null, | ||
| col1Active: equal('activeEditorCol','1'), | ||
| col2Active: equal('activeEditorCol','2'), | ||
|
|
||
| columns: null, | ||
|
|
||
| settings: Settings.create(), | ||
|
|
||
|
|
@@ -69,20 +94,69 @@ export default Ember.Controller.extend({ | |
| }); | ||
| }, | ||
|
|
||
| realNumColumns: computed('numColumns', function() { | ||
| return Math.min(this.get('numColumns'), MAX_COLUMNS); | ||
| }), | ||
| noColumns: computed.equal('numColumns', 0), | ||
|
|
||
| /** | ||
| * Set the initial file columns | ||
| * Creates the column objects | ||
| */ | ||
| initializeColumns: observer('model', function() { | ||
| var files = this.get('model.files'); | ||
| createColumns() { | ||
| let columns = []; | ||
| for (let i = 0; i < MAX_COLUMNS; ++i) { | ||
| let col = (i + 1) + ""; | ||
| columns.pushObject(Column.create({ | ||
| col: col, | ||
| controller: this | ||
| })); | ||
| } | ||
| this.set('columns', columns); | ||
| }, | ||
|
|
||
| if(files.objectAt(0)) { | ||
| this.setColumnFile(1, files.objectAt(0)); | ||
| /** | ||
| * Set the initial files in the columns | ||
| */ | ||
| initializeColumns() { | ||
| let files = this.get('model.files'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i believe we should likley initialize them on-demand, as part of when the columns CP is computed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I really don't like setting and initializing things in computed property getters. |
||
| let numColumns = this.get('realNumColumns'); | ||
|
|
||
| let j = 0; | ||
| for (let i = 1; i <= numColumns; ++i) { | ||
| if (!this.getColumnFile(i)) { | ||
| if (files) { | ||
| j = 0; | ||
| while (!this.isOpen(files.objectAt(j))) { | ||
| j++; | ||
| } | ||
| let file = files.objectAt(j); | ||
| if (file) { | ||
| this.setColumnFile(i, file); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| if(files.objectAt(1)) { | ||
| this.setColumnFile(2, files.objectAt(1)); | ||
| /** | ||
| * Returns true if the passed in file is currently open | ||
| * @param {Object} one of the files in the gist | ||
| * @return {boolean} | ||
| */ | ||
| isOpen(file) { | ||
| if (!file) { | ||
| return false; | ||
| } | ||
|
|
||
| for (let i = 1; i <= MAX_COLUMNS; ++i) { | ||
| let colFile = this.getColumnFile(i); | ||
| if (colFile && colFile.get('fileName') === file.get('fileName')){ | ||
| return false; | ||
| } | ||
| } | ||
| }), | ||
|
|
||
| return true; | ||
| }, | ||
|
|
||
| rebuildApp: function() { | ||
| if (this.get('isLiveReload')) { | ||
|
|
@@ -107,6 +181,7 @@ export default Ember.Controller.extend({ | |
| this.send('contentsChanged'); | ||
| } | ||
| }, | ||
|
|
||
| /* | ||
| * Test whether path is valid. Presently only tests whether components are hyphenated. | ||
| */ | ||
|
|
@@ -123,9 +198,13 @@ export default Ember.Controller.extend({ | |
| } | ||
| return false; | ||
| }, | ||
| setColumnFile(column, file){ | ||
| let fileColumn = `col${column}File`; | ||
| this.set(fileColumn, file); | ||
|
|
||
| getColumnFile(column) { | ||
| return this.get('columns').objectAt(column - 1).get('file'); | ||
| }, | ||
|
|
||
| setColumnFile(column, file) { | ||
| this.get('columns').objectAt(column - 1).set('file', file); | ||
| }, | ||
|
|
||
| actions: { | ||
|
|
@@ -179,6 +258,7 @@ export default Ember.Controller.extend({ | |
| this.createFile(filePath, fileProperties, fileColumn); | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Add a new file to the model | ||
| * @param {String|null} type Blueprint name or null for empty file | ||
|
|
@@ -225,6 +305,32 @@ export default Ember.Controller.extend({ | |
| } | ||
| }, | ||
|
|
||
| removeColumn (col) { | ||
| let numColumns = this.get('realNumColumns'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, it seems like rather then making this controller have array like qualities. Having the columns represented off-object would be clean. Something like: controller.columns === [
col1,
col2,
col3
]columns: computed('dataColumnsNeed', function() {
return ensureColums(this.get('dataColumnsNeed'))
});the return columns object itself doesn't need to be an array, but may prove to be nice if it ways. This would also make it easy to support N columns, if we are so inclined, but also begins to move to a pull based system over the imperative model. some relevant code this would tidy up nicely: |
||
|
|
||
| for (var i = (col|0); i < numColumns; ++i) { | ||
| this.setColumnFile(i, this.getColumnFile(i + 1)); | ||
| } | ||
| this.setColumnFile(numColumns, undefined); | ||
|
|
||
| let activeCol = this.get('activeEditorCol'); | ||
| if (activeCol >= col) { | ||
| this.set('activeEditorCol', ((activeCol|0) - 1).toString()); | ||
| } | ||
|
|
||
| this.transitionToRoute({queryParams: {numColumns: numColumns - 1}}); | ||
| }, | ||
|
|
||
| addColumn() { | ||
| let numColumns = this.get('realNumColumns'); | ||
|
|
||
| this.transitionToRoute({ | ||
| queryParams: { | ||
| numColumns: numColumns + 1 | ||
| } | ||
| }).then(this.initializeColumns.bind(this)); | ||
| }, | ||
|
|
||
| setEditorKeyMap (keyMap) { | ||
| const settings = this.get('settings'); | ||
| settings.set('keyMap', keyMap); | ||
|
|
@@ -233,11 +339,10 @@ export default Ember.Controller.extend({ | |
| }, | ||
|
|
||
| _removeFileFromColumns (file) { | ||
| if(this.get('col1File') === file) { | ||
| this.setColumnFile(1, null); | ||
| } | ||
| if(this.get('col2File') === file) { | ||
| this.setColumnFile(2, null); | ||
| for (let i = 1; i <= MAX_COLUMNS; ++i) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if columns becomes off object, this would become this.get('columns').removeObject(file) |
||
| if (this.getColumnFile(i) === file) { | ||
| this.setColumnFile(i, null); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import Ember from "ember"; | ||
|
|
||
| const { computed } = Ember; | ||
|
|
||
| export default Ember.Object.extend ({ | ||
| col: "", | ||
| controller: null, | ||
| active: computed('controller.activeEditorCol', 'col', function() { | ||
| return this.get('controller.activeEditorCol') === this.get('col'); | ||
| }), | ||
| show: computed('controller.realNumColumns', 'col', function() { | ||
| return this.get('controller.realNumColumns') >= this.get('col'); | ||
| }), | ||
| file: null | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createColumnsshould likely just be the default implementation of the columns CP getterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK, computed property getters with side effects make my head hurt.