From c2b6f6cf872b02c199800b62ac9cbf18162008a3 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Tue, 18 Aug 2015 15:40:23 -0400 Subject: [PATCH 01/13] Start work on file tree --- app/components/file-menu.js | 2 +- app/gist/controller.js | 48 ++++++++++++++++++++++++++++++++++++- app/gist/template.hbs | 36 ++++++++++++++++------------ bower.json | 3 ++- package.json | 30 +++++++++++------------ 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/app/components/file-menu.js b/app/components/file-menu.js index ad5c6644..f2d4c93e 100644 --- a/app/components/file-menu.js +++ b/app/components/file-menu.js @@ -31,7 +31,7 @@ export default Ember.Component.extend({ }, embed() { let src = window.location.href.split("?")[0]; - src += "?numColumns=0"; + src += "?numColumns=0&fullScreen=true"; let iframe = document.createElement("iframe"); iframe.src = src; iframe.width = 800; diff --git a/app/gist/controller.js b/app/gist/controller.js index b4f2cd0b..530c6817 100644 --- a/app/gist/controller.js +++ b/app/gist/controller.js @@ -3,6 +3,7 @@ import config from '../config/environment'; import Settings from '../models/settings'; import ErrorMessages from 'ember-twiddle/helpers/error-messages'; import Column from '../utils/column'; +import _ from 'lodash/lodash'; const { computed, @@ -15,8 +16,9 @@ export default Ember.Controller.extend({ emberCli: Ember.inject.service('ember-cli'), version: config.APP.version, - queryParams: ['numColumns'], + queryParams: ['numColumns', 'fullScreen'], numColumns: 2, + fullScreen: false, init() { this._super(...arguments); @@ -99,6 +101,50 @@ export default Ember.Controller.extend({ }), noColumns: computed.equal('numColumns', 0), + /** + * Calculate data for file tree + */ + fileTreeData: computed('model.files.[]', function() { + let seq = 0; + let treeData = this.get('model.files').map(function(file) { + let path = file.get('filePath'); + let parentPath = path.split("/").slice(0, -1).join("/"); + if (parentPath === "") { + parentPath = "#"; + } + return { + id: "node" + seq++, + text: path, + parent: parentPath + }; + }); + + let paths = _.uniq(_.pluck(treeData, 'text')); + let parents = _.uniq(_.pluck(treeData, 'parent')); + parents.forEach(function(parent) { + if (!paths.contains(parent) && parent !== "#") { + treeData.push({ + id: "node" + seq++, + text: parent, + parent: "#" + }); + } + }); + + let idMap = {}; + treeData.forEach(function(node) { + idMap[node.text] = node.id; + }); + + treeData.forEach(function(node) { + if (node.parent !== "#") { + node.parent = idMap[node.parent]; + } + }); + + return treeData; + }), + /** * Creates the column objects */ diff --git a/app/gist/template.hbs b/app/gist/template.hbs index dc1d46ce..8689888b 100644 --- a/app/gist/template.hbs +++ b/app/gist/template.hbs @@ -31,21 +31,27 @@
- {{#each columns as |column|}} - {{#if column.show}} -
- {{file-editor-column col=column.col - file=column.file - allFiles=model.files - keyMap=settings.keyMap - numColumns=realNumColumns - contentsChanged="contentsChanged" - removeColumn=(action "removeColumn") - addColumn=(action "addColumn") - }} -
- {{/if}} - {{/each}} + {{#unless fullScreen}} +
+ {{ember-jstree data=fileTreeData}} +
+ + {{#each columns as |column|}} + {{#if column.show}} +
+ {{file-editor-column col=column.col + file=column.file + allFiles=model.files + keyMap=settings.keyMap + numColumns=realNumColumns + contentsChanged="contentsChanged" + removeColumn=(action "removeColumn") + addColumn=(action "addColumn") + }} +
+ {{/if}} + {{/each}} + {{/unless}}
diff --git a/bower.json b/bower.json index 01b814ee..a5967b21 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,8 @@ "pretender": "~0.7.0", "ember-inflector": "~1.3.1", "lodash": "~3.10.0", - "Faker": "~3.0.0" + "Faker": "~3.0.0", + "jstree": "~3.2.0" }, "resolutions": { "codemirror": "~5.5.0", diff --git a/package.json b/package.json index 0ec53fdf..77d13dbb 100644 --- a/package.json +++ b/package.json @@ -20,21 +20,6 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.1.2", - "ember-cli": "1.13.8", - "ember-cli-app-version": "0.5.0", - "ember-cli-babel": "^5.1.3", - "ember-cli-dependency-checker": "^1.0.1", - "ember-cli-htmlbars": "0.7.9", - "ember-cli-htmlbars-inline-precompile": "^0.2.0", - "ember-cli-ic-ajax": "0.2.1", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-qunit": "^1.0.0", - "ember-cli-release": "^0.2.5", - "ember-cli-sri": "^1.0.3", - "ember-cli-uglify": "^1.2.0", - "ember-data": "1.13.9", - "ember-disable-proxy-controllers": "^1.0.0", - "ember-export-application-global": "^1.0.3", "broccoli-concat": "0.0.13", "broccoli-funnel": "0.2.3", "broccoli-merge-trees": "0.2.2", @@ -44,15 +29,30 @@ "ember-api-actions": "0.0.7", "ember-autoresize": "0.5.3", "ember-browserify": "^1.0.1", + "ember-cli": "1.13.8", + "ember-cli-app-version": "0.5.0", + "ember-cli-babel": "^5.1.3", "ember-cli-bootstrap-sassy": "0.0.18", "ember-cli-build-notifications": "0.0.3", + "ember-cli-dependency-checker": "^1.0.1", "ember-cli-deploy": "^0.4.2", "ember-cli-file-creator": "^0.1.0", + "ember-cli-htmlbars": "0.7.9", + "ember-cli-htmlbars-inline-precompile": "^0.2.0", + "ember-cli-ic-ajax": "0.2.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-jstree": "0.1.1", "ember-cli-mirage": "0.1.6", + "ember-cli-qunit": "^1.0.0", + "ember-cli-release": "^0.2.5", "ember-cli-sass": "4.0.1", "ember-cli-sri": "^1.0.1", + "ember-cli-uglify": "^1.2.0", + "ember-data": "1.13.9", "ember-deploy-s3": "0.0.5", "ember-deploy-s3-index": "^0.4.0", + "ember-disable-proxy-controllers": "^1.0.0", + "ember-export-application-global": "^1.0.3", "ember-git-version": "0.0.1", "ember-lodash": "0.0.5", "ember-notify": "3.4.0", From 961cb7039aaf44c5677f2f2aa4e429be734bc466 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Tue, 18 Aug 2015 15:50:15 -0400 Subject: [PATCH 02/13] Fix tests --- tests/acceptance/columns-test.js | 2 +- tests/acceptance/gist-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/columns-test.js b/tests/acceptance/columns-test.js index d5532e55..279d126d 100644 --- a/tests/acceptance/columns-test.js +++ b/tests/acceptance/columns-test.js @@ -15,7 +15,7 @@ module('Acceptance | columns', { }); const columns = ".code"; -const firstColumn = ".code:first-of-type"; +const firstColumn = ".code:nth-of-type(2)"; const plusGlyph = ".code .glyphicon-plus"; const removeGlyph = firstColumn + " .glyphicon-remove"; const outputPlusGlyph = ".output .glyphicon-plus"; diff --git a/tests/acceptance/gist-test.js b/tests/acceptance/gist-test.js index 6ffd8859..6e5d9103 100644 --- a/tests/acceptance/gist-test.js +++ b/tests/acceptance/gist-test.js @@ -5,7 +5,7 @@ import { findMapText } from 'ember-twiddle/tests/helpers/util'; import ErrorMessages from 'ember-twiddle/helpers/error-messages'; -const firstColumn = '.code:first-of-type'; +const firstColumn = '.code:nth-of-type(2)'; const firstFilePicker = firstColumn + ' .dropdown-toggle'; const secondFile = firstColumn + ' .dropdown-menu li:nth-child(2) a'; const anyFile = firstColumn + ' .dropdown-menu li:nth-child(1) a'; From 22ee51a9afa972ac9ad6993f9cd10f50c94cdbf8 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Wed, 19 Aug 2015 14:44:45 -0400 Subject: [PATCH 03/13] Allow exit from full screen --- app/components/file-menu.js | 2 +- app/gist/controller.js | 8 ++++++++ app/gist/template.hbs | 5 ++++- app/styles/app.scss | 22 ++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/components/file-menu.js b/app/components/file-menu.js index f2d4c93e..60f9f35f 100644 --- a/app/components/file-menu.js +++ b/app/components/file-menu.js @@ -31,7 +31,7 @@ export default Ember.Component.extend({ }, embed() { let src = window.location.href.split("?")[0]; - src += "?numColumns=0&fullScreen=true"; + src += "?fullScreen=true"; let iframe = document.createElement("iframe"); iframe.src = src; iframe.width = 800; diff --git a/app/gist/controller.js b/app/gist/controller.js index 530c6817..686da542 100644 --- a/app/gist/controller.js +++ b/app/gist/controller.js @@ -377,6 +377,14 @@ export default Ember.Controller.extend({ }).then(this.initializeColumns.bind(this)); }, + exitFullScreen() { + this.transitionToRoute({ + queryParams: { + fullScreen: false + } + }).then(this.initializeColumns.bind(this)); + }, + setEditorKeyMap (keyMap) { const settings = this.get('settings'); settings.set('keyMap', keyMap); diff --git a/app/gist/template.hbs b/app/gist/template.hbs index 8689888b..8887f32d 100644 --- a/app/gist/template.hbs +++ b/app/gist/template.hbs @@ -53,7 +53,7 @@ {{/each}} {{/unless}} -
+
{{#if noColumns}} @@ -68,6 +68,9 @@
{{applicationUrl}}
{{dummy-demo-app html=buildOutput}} + {{#if fullScreen}} + Edit Twiddle + {{/if}}
diff --git a/app/styles/app.scss b/app/styles/app.scss index edc91d9e..a7e83bd3 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -257,6 +257,28 @@ body { } } } + + .full-screen { + .header { + display: none; + } + + .run-or-live-reload { + display: none; + } + } + + .exit-full-screen-link { + display: block; + position: absolute; + bottom: 20px; + left: 50%; + width: 100px; + margin-left: -50px; + text-align: center; + color: $dropdown-link-color; + cursor: pointer; + } } .dropdown { From 954b08511c463c62403ee58812061570c08a7823 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Wed, 19 Aug 2015 15:09:54 -0400 Subject: [PATCH 04/13] Hide file tree by default --- app/components/file-editor-column.js | 10 ++++++++++ app/gist/controller.js | 13 +++++++++++++ app/gist/template.hbs | 10 +++++++--- app/styles/app.scss | 18 ++++++++++++++---- .../components/file-editor-column.hbs | 5 +++++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/components/file-editor-column.js b/app/components/file-editor-column.js index 62ed54ae..3376b355 100644 --- a/app/components/file-editor-column.js +++ b/app/components/file-editor-column.js @@ -26,6 +26,12 @@ export default Ember.Component.extend({ return (this.get('col') | 0) === numColumns && numColumns < MAX_COLUMNS; }), + isFirstColumn: computed.equal('col', '1'), + + showFileTreeOpenIcon: computed('isFirstColumn', 'fileTreeShown', function() { + return this.get('isFirstColumn') && !this.get('fileTreeShown'); + }), + focusIn () { this.sendAction('focusEditor', this); }, @@ -46,6 +52,10 @@ export default Ember.Component.extend({ addColumn() { this.attrs.addColumn(); + }, + + showFileTree() { + this.attrs.showFileTree(); } } }); diff --git a/app/gist/controller.js b/app/gist/controller.js index 686da542..0a2987be 100644 --- a/app/gist/controller.js +++ b/app/gist/controller.js @@ -72,6 +72,11 @@ export default Ember.Controller.extend({ */ isLiveReload: true, + /** + * Whether the file tree is currently shown + */ + fileTreeShown: false, + /** * Build the application and set the iframe code */ @@ -277,6 +282,14 @@ export default Ember.Controller.extend({ this.buildApp(); }, + showFileTree() { + this.set('fileTreeShown', true); + }, + + hideFileTree() { + this.set('fileTreeShown', false); + }, + deleteGist (gist) { if(confirm(`Are you sure you want to remove this gist from Github?\n\n${gist.get('description')}`)) { gist.destroyRecord(); diff --git a/app/gist/template.hbs b/app/gist/template.hbs index 8887f32d..8e4ce5d8 100644 --- a/app/gist/template.hbs +++ b/app/gist/template.hbs @@ -32,9 +32,11 @@
{{#unless fullScreen}} -
- {{ember-jstree data=fileTreeData}} -
+ {{#if fileTreeShown}} +
+ {{ember-jstree data=fileTreeData}} +
+ {{/if}} {{#each columns as |column|}} {{#if column.show}} @@ -44,9 +46,11 @@ allFiles=model.files keyMap=settings.keyMap numColumns=realNumColumns + fileTreeShown=fileTreeShown contentsChanged="contentsChanged" removeColumn=(action "removeColumn") addColumn=(action "addColumn") + showFileTree=(action "showFileTree") }}
{{/if}} diff --git a/app/styles/app.scss b/app/styles/app.scss index a7e83bd3..ea595305 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -239,6 +239,12 @@ body { background-color: #faf4f1; position: relative; + .nav-left { + position: absolute; + top: 18px; + left: 15px; + } + .file-picker { margin-left: 15px; margin-top: 8px; @@ -246,15 +252,19 @@ body { position: absolute; } + .nav-left+.file-picker { + margin-left: 30px; + } + .nav-right { position: absolute; top: 20px; right: 15px; + } - .glyphicon { - color: $navbar-default-link-color; - cursor: pointer; - } + .glyphicon { + color: $navbar-default-link-color; + cursor: pointer; } } diff --git a/app/templates/components/file-editor-column.hbs b/app/templates/components/file-editor-column.hbs index f42ba349..09a646a6 100644 --- a/app/templates/components/file-editor-column.hbs +++ b/app/templates/components/file-editor-column.hbs @@ -1,4 +1,9 @@
+ {{#if showFileTreeOpenIcon}} + + + + {{/if}}