瀏覽代碼

Merge branch 'master-redesign' of github.com:sharelatex/web-sharelatex into master-redesign

James Allen 12 年之前
父節點
當前提交
8e1593bb96

+ 1 - 1
services/web/app/coffee/Features/Project/ProjectController.coffee

@@ -145,7 +145,7 @@ module.exports = ProjectController =
 
 					if Settings?.algolia?.app_id? and Settings?.algolia?.read_only_api_key?
 						viewModel.showUserDetailsArea = true
-						viewModel.algolia_api_key = Settings.algolia.api_key
+						viewModel.algolia_api_key = Settings.algolia.read_only_api_key
 						viewModel.algolia_app_id = Settings.algolia.app_id
 					else
 						viewModel.showUserDetailsArea = false

+ 4 - 0
services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee

@@ -22,6 +22,10 @@ module.exports =
 				logger.log project_id:project_id, details:details, "getting project details"
 				callback(err, details)
 
+	getProjectDescription: (project_id, callback)->
+		Project.findOne _id:project_id, "description", (err, project)->
+			callback(err, project?.description)
+
 	setProjectDescription: (project_id, description, callback)->
 		conditions = _id:project_id
 		update = description:description

+ 11 - 1
services/web/app/coffee/Features/Templates/TemplatesController.coffee

@@ -1,12 +1,14 @@
 path = require('path')
 ProjectUploadManager = require('../Uploads/ProjectUploadManager')
 ProjectOptionsHandler = require("../Project/ProjectOptionsHandler")
+ProjectDetailsHandler = require('../Project/ProjectDetailsHandler')
 TemplatesPublisher = require("./TemplatesPublisher")
 settings = require('settings-sharelatex')
 fs = require('fs')
 request = require('request')
 uuid = require('node-uuid')
 logger = require('logger-sharelatex')
+async = require("async")
 
 
 module.exports =
@@ -43,9 +45,17 @@ module.exports =
 		TemplatesPublisher.unpublish user_id, project_id, callback
 
 	getTemplateDetails: (user_id, project_id, callback)->
-		TemplatesPublisher.getTemplateDetails user_id, project_id, (err, details)->
+		async.parallel {
+			details: (cb)->
+				TemplatesPublisher.getTemplateDetails user_id, project_id, cb
+			description: (cb)->
+				ProjectDetailsHandler.getProjectDescription project_id, cb
+		}, (err, results)->
 			if err?
 				logger.err err:err, user_id:user_id, project_id:project_id, "something went wrong getting template details"
+				return callback(err)
+			details = results.details
+			details.description = results.description
 			callback(err, details)
 
 

+ 0 - 1
services/web/app/views/project/editor.jade

@@ -104,7 +104,6 @@ block content
 				}
 			}
 		};
-		window.project_description = "#{project.description}"
 
 	script(type='text/javascript').
 		ga('send', 'event', 'editor-interaction', 'editor-opened')

+ 1 - 1
services/web/app/views/project/editor/left-menu.jade

@@ -108,7 +108,7 @@ aside#left-menu.full-size(
 		ul.list-unstyled.nav()
 			li
 				a(ng-click="openPublishTemplateModal()")
-					i.fa.fa-list-alt.fa-fw 
+					i.fa.fa-external-link.fa-fw 
 					|   Publish as Template
 
 

+ 30 - 23
services/web/app/views/project/editor/publish-template.jade

@@ -7,39 +7,46 @@ script(type="text/ng-template", id="publishProjectAsTemplateModalTemplate")
 		) ×
 		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.
+		span(ng-hide="problemTalkingToTemplateApi")
+			form()
+				label(for='Description') Template Description
+				.form-group
+					textarea.form-control(
+					rows=5,
+					name='Description',
+					ng-model="templateDetails.description",
+					ng-blur="updateProjectDescription()",
+					value=""
+				)
+			div(ng-show="templateDetails.exists").text-center.templateDetails
+				|  Your project was last published at 
+				strong {{templateDetails.publishedDate}}. 
+				a(ng-href="{{templateDetails.canonicalUrl}}") View it in template gallery.
 
+		span(ng-show="problemTalkingToTemplateApi") There is a problem with our publishing service, please try again in a few minutes.
 
 
-	.modal-footer
+
+
+	.modal-footer(ng-hide="problemTalkingToTemplateApi")
 		button.btn.btn-default(
 			ng-click="cancel()",
-			ng-disabled="state.publishInflight"
-		) Cancel
+			ng-disabled="state.publishInflight || state.unpublishInflight"
+		)
+			span Cancel
+
 		button.btn.btn-info(
 			ng-click="unpublishTemplate()",
-			ng-disabled="state.unpublishInflight",
-			ng-show="publishedDetails.exists"
+			ng-disabled="state.publishInflight || state.unpublishInflight"
+			ng-show="templateDetails.exists"
 		) 
 			span(ng-show="!state.unpublishInflight") Unpublish
 			span(ng-show="state.unpublishInflight") Unpublishing...
+
 		button.btn.btn-primary(
-			ng-click="publish()",
-			ng-disabled="state.publishInflight"
+			ng-click="publishTemplate()",
+			ng-disabled="state.publishInflight || state.unpublishInflight"
 		)
-			span(ng-show="!state.publishInflight && !publishedDetails.exists") Publish
-			span(ng-show="!state.publishInflight && publishedDetails.exists") Republish
+			span(ng-show="!state.publishInflight && !templateDetails.exists") Publish
+			span(ng-show="!state.publishInflight && templateDetails.exists") Republish
 			span(ng-show="state.publishInflight") Publishing...

+ 25 - 14
services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee

@@ -2,48 +2,59 @@ define [
 	"base"
 	"ide/permissions/PermissionsManager"
 ], (App, PermissionsManager) ->
+
 	App.controller "TemplatesController", ($scope, $modal, ide) ->
 		$scope.openPublishTemplateModal = () ->
-			$modal.open {
+			resetState = ->
+				$scope.problemTalkingToTemplateApi = false
+
+			resetState()
+
+			modal = $modal.open {
 				templateUrl: "publishProjectAsTemplateModalTemplate"
 				controller: "PublishProjectAsTemplateModalController"
-				resolve:
-					diff: () -> $scope.trackChanges.diff
+				scope:$scope
 			}
+			modal.result.then(resetState, resetState)
 
 	App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
-		permissionsManager = new PermissionsManager(ide, $scope)
 		user_id = ide.$scope.user.id
-		$scope.template =
-			description: window.project_description
-		$scope.publishedDetails =
-			exists:false
+		$scope.templateDetails = {exists:false}
 
 		$scope.state =
 			publishInflight: false
 			unpublishInflight: false
 
+		problemTalkingToTemplateApi = ->
+			$scope.problemTalkingToTemplateApi = true
+
 		refreshPublishedStatus = ->
 			ide.socket.emit "getPublishedDetails", user_id, (err, data)->
-				$scope.publishedDetails = data
-				$scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
+				if !data? or err? then return problemTalkingToTemplateApi()
+				$scope.templateDetails = data
+				$scope.templateDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
+				$scope.templateDetails.description = data.description
 
 		refreshPublishedStatus()
+		$scope.$watch $scope.problemTalkingToTemplateApi, refreshPublishedStatus
 
 		$scope.updateProjectDescription = ->
 			description = $scope.template.description
 			if description?
-				ide.socket.emit 'updateProjectDescription', description, () => 
+				ide.socket.emit 'updateProjectDescription', description, (err) => 
+					if err? then return problemTalkingToTemplateApi()
 
-		$scope.publish = ->
+		$scope.publishTemplate = ->
 			$scope.state.publishInflight = true
-			ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) =>
+			ide.socket.emit 'publishProjectAsTemplate', user_id, (error) =>
+				if err? then return problemTalkingToTemplateApi()
 				refreshPublishedStatus()
 				$scope.state.publishInflight = false
 
 		$scope.unpublishTemplate = ->
 			$scope.state.unpublishInflight = true
-			ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) =>
+			ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error) =>
+				if err? then return problemTalkingToTemplateApi()
 				refreshPublishedStatus()
 				$scope.state.unpublishInflight = false
 

+ 20 - 0
services/web/test/UnitTests/coffee/Project/ProjectDetailsHandlerTests.coffee

@@ -23,6 +23,7 @@ describe 'Project details handler', ->
 			getProject: sinon.stub().callsArgWith(2, null, @project)
 		@ProjectModel =
 			update: sinon.stub()
+			findOne: sinon.stub()
 		@UserGetter =
 			getUser: sinon.stub().callsArgWith(1, null, @user)
 		@tpdsUpdateSender =
@@ -54,6 +55,23 @@ describe 'Project details handler', ->
 				err.should.equal error
 				done()
 
+	describe "getProjectDescription", ->
+
+		it "should make a call to mongo just for the description", (done)->
+			@ProjectModel.findOne.callsArgWith(2)
+			@handler.getProjectDescription @project_id, (err, description)=>
+				@ProjectModel.findOne.calledWith({_id:@project_id}, "description").should.equal true
+				done()
+
+		it "should return what the mongo call returns", (done)->
+			err = "error"
+			description = "cool project"
+			@ProjectModel.findOne.callsArgWith(2, err, {description:description})
+			@handler.getProjectDescription @project_id, (returnedErr, returnedDescription)=>
+				err.should.equal returnedErr
+				description.should.equal returnedDescription
+				done()	
+
 	describe "setProjectDescription", ->
 
 		beforeEach ->
@@ -65,6 +83,8 @@ describe 'Project details handler', ->
 				@ProjectModel.update.calledWith({_id:@project_id}, {description:@description}).should.equal true
 				done()
 
+
+
 	describe "renameProject", ->
 		beforeEach ->
 			@ProjectModel.update.callsArgWith(2)

+ 13 - 0
services/web/test/UnitTests/coffee/Templates/TemplatesControllerTests.coffee

@@ -25,9 +25,12 @@ describe 'TemplatesController', ->
 			publish: sinon.stub()
 			unpublish:sinon.stub()
 			getTemplateDetails: sinon.stub()
+		@ProjectDetailsHandler =
+			getProjectDescription:sinon.stub()
 		@controller = SandboxedModule.require modulePath, requires:
 			'../Uploads/ProjectUploadManager':@ProjectUploadManager
 			'../Project/ProjectOptionsHandler':@ProjectOptionsHandler
+			'../Project/ProjectDetailsHandler':@ProjectDetailsHandler
 			'./TemplatesPublisher':@TemplatesPublisher
 			"logger-sharelatex": 
 				log:->
@@ -138,6 +141,9 @@ describe 'TemplatesController', ->
 
 
 	describe 'getTemplateDetails', ->
+		beforeEach ->
+			@description = "this project is nice"
+			@ProjectDetailsHandler.getProjectDescription.callsArgWith(1, null, @description)
 
 		it "should return an error the templatePublisher", (done)->
 			error = "error"
@@ -152,3 +158,10 @@ describe 'TemplatesController', ->
 			@controller.getTemplateDetails @user_id, @project_id, (err, passedDetails)=>
 				details.should.equal passedDetails
 				done()
+
+		it "should get the template description", (done)->
+			@TemplatesPublisher.getTemplateDetails.callsArgWith(2, null, {})
+			@controller.getTemplateDetails @user_id, @project_id, (err, passedDetails)=>
+				passedDetails.description.should.equal @description
+				done()
+

+ 4 - 1
services/web/test/UnitTests/coffee/Templates/TemplatesPublisherTests.coffee

@@ -20,7 +20,10 @@ describe 'Templates publish', ->
 		@TemplatesPublisher = SandboxedModule.require modulePath, requires:
 			"request": @request
 			"settings-sharelatex":@settings
-
+			"logger-sharelatex": 
+				log:->
+				err:->
+					
 		@project_id = "12312132"
 		@user_id = "132jlkjdsaoij"