Get public sharing modal working

This commit is contained in:
James Allen 2014-07-01 15:05:32 +01:00
parent d599cfa7ac
commit 9839f3fc62
8 changed files with 178 additions and 67 deletions

View file

@ -3,7 +3,7 @@ aside#left-menu.full-size(
ng-cloak
)
h4 Settings
form
form(ng-controller="SettingsController")
.form-controls
label(for="compiler") Compiler
select.form-control(

View file

@ -1,12 +1,29 @@
script(type='text/ng-template', id='shareProjectModalTemplate')
.modal-header
button.close(
type="button"
data-dismiss="modal"
ng-click="cancel()"
) ×
h3 Share Project
.modal-body.modal-body-share
.container-fluid
.row.public-access-level
.row.public-access-level(ng-show="project.publicAccesLevel == 'private'")
.col-md-9 This project is private and can only be accessed by the people below.
.col-md-3.text-right
a(href) Make public
a(
href
ng-click="openMakePublicModal()"
) Make Public
.row.public-access-level(ng-show="project.publicAccesLevel != 'private'")
.col-md-9
strong(ng-if="project.publicAccesLevel == 'readAndWrite'") This project is public and can be edited by anyone with the URL.
strong(ng-if="project.publicAccesLevel == 'readOnly'") This project is public and can be viewed by anyone with the URL.
.col-md-3.text-right
a(
href
ng-click="openMakePrivateModal()"
) Make Private
.row.project-member
.col-md-8 {{ project.owner.email }}
.text-right(
@ -61,4 +78,47 @@ script(type='text/ng-template', id='shareProjectModalTemplate')
span.text-danger.error(ng-show="state.error") {{ state.error }}
button.btn.btn-primary(
ng-click="done()"
) Done
) Done
script(type="text/ng-template", id="makePublicModalTemplate")
.modal-header
button.close(
type="button"
data-dismiss="modal"
ng-click="cancel()"
) ×
h3 Make project public?
.modal-body.modal-body-share
p If you make your project public then anyone with the URL will be able to access it.
p
select.form-control(
ng-model="inputs.privileges"
name="privileges"
)
option(value="readAndWrite") Allow public editing
option(value="readOnly") Allow public read only access
.modal-footer
button.btn.btn-default(
ng-click="cancel()"
) Cancel
button.btn.btn-info(
ng-click="makePublic()"
) Make public
script(type="text/ng-template", id="makePrivateModalTemplate")
.modal-header
button.close(
type="button"
data-dismiss="modal"
ng-click="cancel()"
) ×
h3 Make project private?
.modal-body.modal-body-share
p If you make your project public then only the people you choose to share it with will have access.
.modal-footer
button.btn.btn-default(
ng-click="cancel()"
) Cancel
button.btn.btn-info(
ng-click="makePrivate()"
) Make private

View file

@ -3,10 +3,10 @@ define [
"ide/file-tree/FileTreeManager"
"ide/connection/ConnectionManager"
"ide/editor/EditorManager"
"ide/settings/SettingsManager"
"ide/online-users/OnlineUsersManager"
"ide/track-changes/TrackChangesManager"
"ide/pdf/PdfManager"
"ide/settings/index"
"ide/share/index"
"ide/directives/layout"
"ide/services/ide"
@ -19,7 +19,6 @@ define [
FileTreeManager
ConnectionManager
EditorManager
SettingsManager
OnlineUsersManager
TrackChangesManager
PdfManager
@ -43,6 +42,7 @@ define [
view: "editor"
}
$scope.user = window.user
$scope.settings = window.userSettings
window._ide = ide
@ -52,7 +52,6 @@ define [
ide.connectionManager = new ConnectionManager(ide, $scope)
ide.fileTreeManager = new FileTreeManager(ide, $scope)
ide.editorManager = new EditorManager(ide, $scope)
ide.settingsManager = new SettingsManager(ide, $scope)
ide.onlineUsersManager = new OnlineUsersManager(ide, $scope)
ide.trackChangesManager = new TrackChangesManager(ide, $scope)
ide.pdfManager = new PdfManager(ide, $scope)

View file

@ -1,59 +0,0 @@
define [], () ->
class SettingsManager
constructor: (@ide, @$scope) ->
@$scope.settings = window.userSettings
if @$scope.settings.mode not in ["default", "vim", "emacs"]
@$scope.settings.mode = "default"
@$scope.$watch "settings.theme", (theme, oldTheme) =>
if theme != oldTheme
@saveSettings({theme: theme})
@$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
if fontSize != oldFontSize
@saveSettings({fontSize: parseInt(fontSize, 10)})
@$scope.$watch "settings.mode", (mode, oldMode) =>
if mode != oldMode
@saveSettings({mode: mode})
@$scope.$watch "settings.autoComplete", (autoComplete, oldAutoComplete) =>
if autoComplete != oldAutoComplete
@saveSettings({autoComplete: autoComplete})
@$scope.$watch "settings.pdfViewer", (pdfViewer, oldPdfViewer) =>
if pdfViewer != oldPdfViewer
@saveSettings({pdfViewer: pdfViewer})
@$scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
return if @ignoreUpdates
if oldLanguage? and language != oldLanguage
@saveProjectSettings({spellCheckLanguage: language})
# Also set it as the default for the user
@saveSettings({spellCheckLanguage: language})
@$scope.$watch "project.compiler", (compiler, oldCompiler) =>
return if @ignoreUpdates
if oldCompiler? and compiler != oldCompiler
@saveProjectSettings({compiler: compiler})
@ide.socket.on "compilerUpdated", (compiler) =>
@ignoreUpdates = true
@$scope.$apply () =>
@$scope.project.compiler = compiler
delete @ignoreUpdates
@ide.socket.on "spellCheckLanguageUpdated", (languageCode) =>
@ignoreUpdates = true
@$scope.$apply () =>
@$scope.project.spellCheckLanguage = languageCode
delete @ignoreUpdates
saveSettings: (data) ->
data._csrf = window.csrfToken
@ide.$http.post "/user/settings", data
saveProjectSettings: (data) ->
data._csrf = window.csrfToken
@ide.$http.post "/project/#{@ide.project_id}/settings", data

View file

@ -0,0 +1,51 @@
define [
"base"
], (App) ->
App.controller "SettingsController", ["$scope", "settings", "ide", ($scope, settings, ide) ->
if $scope.settings.mode not in ["default", "vim", "emacs"]
$scope.settings.mode = "default"
$scope.$watch "settings.theme", (theme, oldTheme) =>
if theme != oldTheme
settings.saveSettings({theme: theme})
$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
if fontSize != oldFontSize
settings.saveSettings({fontSize: parseInt(fontSize, 10)})
$scope.$watch "settings.mode", (mode, oldMode) =>
if mode != oldMode
settings.saveSettings({mode: mode})
$scope.$watch "settings.autoComplete", (autoComplete, oldAutoComplete) =>
if autoComplete != oldAutoComplete
settings.saveSettings({autoComplete: autoComplete})
$scope.$watch "settings.pdfViewer", (pdfViewer, oldPdfViewer) =>
if pdfViewer != oldPdfViewer
settings.saveSettings({pdfViewer: pdfViewer})
$scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
return if @ignoreUpdates
if oldLanguage? and language != oldLanguage
settings.saveProjectSettings({spellCheckLanguage: language})
# Also set it as the default for the user
settings.saveSettings({spellCheckLanguage: language})
$scope.$watch "project.compiler", (compiler, oldCompiler) =>
return if @ignoreUpdates
if oldCompiler? and compiler != oldCompiler
settings.saveProjectSettings({compiler: compiler})
ide.socket.on "compilerUpdated", (compiler) =>
@ignoreUpdates = true
$scope.$apply () =>
$scope.project.compiler = compiler
delete @ignoreUpdates
ide.socket.on "spellCheckLanguageUpdated", (languageCode) =>
@ignoreUpdates = true
$scope.$apply () =>
$scope.project.spellCheckLanguage = languageCode
delete @ignoreUpdates
]

View file

@ -0,0 +1,5 @@
define [
"ide/settings/services/settings"
"ide/settings/controllers/SettingsController"
], () ->

View file

@ -0,0 +1,14 @@
define [
"base"
], (App) ->
App.factory "settings", ["ide", (ide) ->
return {
saveSettings: (data) ->
data._csrf = window.csrfToken
ide.$http.post "/user/settings", data
saveProjectSettings: (data) ->
data._csrf = window.csrfToken
ide.$http.post "/project/#{ide.project_id}/settings", data
}
]

View file

@ -1,7 +1,7 @@
define [
"base"
], (App) ->
App.controller "ShareProjectModalController", ["$scope", "$modalInstance", "$timeout", "projectMembers", ($scope, $modalInstance, $timeout, projectMembers) ->
App.controller "ShareProjectModalController", ["$scope", "$modalInstance", "$timeout", "projectMembers", "$modal", ($scope, $modalInstance, $timeout, projectMembers, $modal) ->
$scope.inputs = {
privileges: "readAndWrite"
email: ""
@ -58,6 +58,47 @@ define [
window.open("/user/subscription/plans")
$scope.state.startedFreeTrial = true
$scope.openMakePublicModal = () ->
$modal.open {
templateUrl: "makePublicModalTemplate"
controller: "MakePublicModalController"
scope: $scope
}
$scope.openMakePrivateModal = () ->
$modal.open {
templateUrl: "makePrivateModalTemplate"
controller: "MakePrivateModalController"
scope: $scope
}
$scope.done = () ->
$modalInstance.close()
$scope.cancel = () ->
$modalInstance.dismiss()
]
App.controller "MakePublicModalController", ["$scope", "$modalInstance", "settings", ($scope, $modalInstance, settings) ->
$scope.inputs = {
privileges: "readAndWrite"
}
$scope.makePublic = () ->
$scope.project.publicAccesLevel = $scope.inputs.privileges
settings.saveProjectSettings({publicAccessLevel: $scope.inputs.privileges})
$modalInstance.close()
$scope.cancel = () ->
$modalInstance.dismiss()
]
App.controller "MakePrivateModalController", ["$scope", "$modalInstance", "settings", ($scope, $modalInstance, settings) ->
$scope.makePrivate = () ->
$scope.project.publicAccesLevel = "private"
settings.saveProjectSettings({publicAccessLevel: "private"})
$modalInstance.close()
$scope.cancel = () ->
$modalInstance.dismiss()
]