From d39b8a0a059b4513bcc243146d6b60ff19cea29c Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 15 Jul 2014 14:28:39 +0100 Subject: [PATCH 1/2] fixed broken chat test --- .../test/UnitTests/coffee/Chat/ChatControllerTests.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee b/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee index c7bc1e952d..8fa69097c6 100644 --- a/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Chat/ChatControllerTests.coffee @@ -68,7 +68,8 @@ describe "ChatController", -> it "should return the messages", (done)-> messages = [{content:"hello"}] @ChatHandler.getMessages.callsArgWith(2, null, messages) - @ChatController.getMessages @project_id, @query, (err, passedMessages)=> - passedMessages.should.deep.equal messages + @res.send = (sentMessages)=> + sentMessages.should.deep.equal messages done() + @ChatController.getMessages @req, @res From c93c8b3f7df9affb0e56dbeb6fd170bf469d2c30 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 15 Jul 2014 17:56:09 +0100 Subject: [PATCH 2/2] got basic client side templates --- services/web/app/views/project/editor.jade | 2 + .../app/views/project/editor/left-menu.jade | 7 +++ .../project/editor/publish-template.jade | 45 +++++++++++++++ services/web/public/coffee/ide.coffee | 1 + .../controllers/TemplatesController.coffee | 55 +++++++++++++++++++ .../public/coffee/ide/templates/index.coffee | 4 ++ .../web/public/stylesheets/app/editor.less | 1 + .../app/editor/publish-template.less | 3 + 8 files changed, 118 insertions(+) create mode 100644 services/web/app/views/project/editor/publish-template.jade create mode 100644 services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee create mode 100644 services/web/public/coffee/ide/templates/index.coffee create mode 100644 services/web/public/stylesheets/app/editor/publish-template.less diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 67d73c83f1..1ba1a3e367 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -59,6 +59,7 @@ block content include ./editor/editor include ./editor/binary-file include ./editor/track-changes + include ./editor/publish-template .ui-layout-east //- include ./editor/chat @@ -101,6 +102,7 @@ block content } } }; + window.project_description = "#{project.description}" script(type='text/javascript'). ga('send', 'event', 'editor-interaction', 'editor-opened') diff --git a/services/web/app/views/project/editor/left-menu.jade b/services/web/app/views/project/editor/left-menu.jade index 2bd16d602b..ea1f141671 100644 --- a/services/web/app/views/project/editor/left-menu.jade +++ b/services/web/app/views/project/editor/left-menu.jade @@ -110,6 +110,13 @@ aside#left-menu.full-size( ) option(value="pdfjs") Built-In option(value="native") Native + h4 Publish + ul.list-unstyled.nav(ng-controller="TemplatesController") + li + a(ng-click="openPublishTemplateModal()") + i.fa.fa-list-alt.fa-fw + |   Publish as Template + #left-menu-mask( ng-show="ui.leftMenuShown", diff --git a/services/web/app/views/project/editor/publish-template.jade b/services/web/app/views/project/editor/publish-template.jade new file mode 100644 index 0000000000..0fbd07618c --- /dev/null +++ b/services/web/app/views/project/editor/publish-template.jade @@ -0,0 +1,45 @@ +script(type="text/ng-template", id="publishProjectAsTemplateModalTemplate") + .modal-header + button.close( + type="button" + data-dismiss="modal" + ng-click="cancel()" + ) × + h3 Publish as Template + .modal-body.modal-body-share + form() + label(for='Description') Template Description + .form-group + textarea.form-control( + rows=5, + name='Description', + ng-model="template.description", + ng-blur="updateProjectDescription()", + value="" + ) + div(ng-show="publishedDetails.exists").text-center.publishedDetails + | Your project was last published at + strong {{publishedDetails.publishedDate}}. + a(ng-href="{{publishedDetails.canonicalUrl}}") View it in template gallery. + + + + .modal-footer + button.btn.btn-default( + ng-click="cancel()", + ng-disabled="state.publishInflight" + ) Cancel + button.btn.btn-info( + ng-click="unpublishTemplate()", + ng-disabled="state.unpublishInflight", + ng-show="publishedDetails.exists" + ) + span(ng-show="!state.unpublishInflight") Unpublish + span(ng-show="state.unpublishInflight") Unpublishing... + button.btn.btn-primary( + ng-click="publish()", + ng-disabled="state.publishInflight" + ) + span(ng-show="!state.publishInflight && !publishedDetails.exists") Publish + span(ng-show="!state.publishInflight && publishedDetails.exists") Republish + span(ng-show="state.publishInflight") Publishing... \ No newline at end of file diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 8b5913a18e..9ec93d9890 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -11,6 +11,7 @@ define [ "ide/settings/index" "ide/share/index" "ide/chat/index" + "ide/templates/index" "ide/directives/layout" "ide/services/ide" "directives/focus" diff --git a/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee b/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee new file mode 100644 index 0000000000..e71e4eab42 --- /dev/null +++ b/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee @@ -0,0 +1,55 @@ +define [ + "base" +], (App) -> + App.controller "TemplatesController", ($scope, $modal, ide) -> + + $scope.openPublishTemplateModal = () -> + console.log "open" + $modal.open { + templateUrl: "publishProjectAsTemplateModalTemplate" + controller: "PublishProjectAsTemplateModalController" + resolve: + diff: () -> $scope.trackChanges.diff + } + + App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, diff, ide) -> + user_id = window.user.id #TODO this is not correct, it needs to be the owners id + $scope.template = + description: window.project_description + $scope.publishedDetails = + exists:false + + $scope.state = + publishInflight: false + unpublishInflight: false + + refreshPublishedStatus = -> + ide.socket.emit "getPublishedDetails", user_id, (err, data)-> + console.log "got published details" + $scope.publishedDetails = data + $scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a") + + refreshPublishedStatus() + + $scope.updateProjectDescription = -> + description = $scope.template.description + if description? + ide.socket.emit 'updateProjectDescription', description, () => + console.log "updated" + + $scope.publish = -> + $scope.state.publishInflight = true + ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) => + console.log "published" + refreshPublishedStatus() + $scope.state.publishInflight = false + + $scope.unpublishTemplate = -> + $scope.state.unpublishInflight = true + ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) => + console.log "unpublished" + refreshPublishedStatus() + $scope.state.unpublishInflight = false + + $scope.cancel = () -> + $modalInstance.dismiss() diff --git a/services/web/public/coffee/ide/templates/index.coffee b/services/web/public/coffee/ide/templates/index.coffee new file mode 100644 index 0000000000..10d7872e9c --- /dev/null +++ b/services/web/public/coffee/ide/templates/index.coffee @@ -0,0 +1,4 @@ +define [ + "ide/templates/controllers/TemplatesController" +], () -> + diff --git a/services/web/public/stylesheets/app/editor.less b/services/web/public/stylesheets/app/editor.less index 9e9f5e380b..9a72122669 100644 --- a/services/web/public/stylesheets/app/editor.less +++ b/services/web/public/stylesheets/app/editor.less @@ -7,6 +7,7 @@ @import "./editor/chat.less"; @import "./editor/binary-file.less"; @import "./editor/search.less"; +@import "./editor/publish-template.less"; .full-size { position: absolute; diff --git a/services/web/public/stylesheets/app/editor/publish-template.less b/services/web/public/stylesheets/app/editor/publish-template.less new file mode 100644 index 0000000000..b57d8dccdc --- /dev/null +++ b/services/web/public/stylesheets/app/editor/publish-template.less @@ -0,0 +1,3 @@ +.publishedDetails { + color: @gray; +}