mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Use promise method signatures, instead of old HTTP service ones.
This commit is contained in:
@@ -28,16 +28,17 @@ define [
|
||||
# authentication fails, we will handle it ourselves
|
||||
$http
|
||||
.post(element.attr('action'), formData, {disableAutoLoginRedirect: true})
|
||||
.then (data, status, headers, config) ->
|
||||
.then (httpResponse) ->
|
||||
{ data, status, headers, config } = httpResponse
|
||||
scope[attrs.name].inflight = false
|
||||
response.success = true
|
||||
response.error = false
|
||||
|
||||
onSuccessHandler = scope[attrs.onSuccess]
|
||||
if onSuccessHandler
|
||||
onSuccessHandler(data, status, headers, config)
|
||||
onSuccessHandler(httpResponse)
|
||||
return
|
||||
|
||||
|
||||
if data.redir?
|
||||
ga('send', 'event', formName, 'success')
|
||||
window.location = data.redir
|
||||
@@ -51,14 +52,15 @@ define [
|
||||
else
|
||||
ga('send', 'event', formName, 'success')
|
||||
|
||||
.catch (data, status, headers, config) ->
|
||||
.catch (httpResponse) ->
|
||||
{ data, status, headers, config } = httpResponse
|
||||
scope[attrs.name].inflight = false
|
||||
response.success = false
|
||||
response.error = true
|
||||
|
||||
onErrorHandler = scope[attrs.onError]
|
||||
if onErrorHandler
|
||||
onErrorHandler(data, status, headers, config)
|
||||
onErrorHandler(httpResponse)
|
||||
return
|
||||
|
||||
if status == 403 # Forbidden
|
||||
|
||||
@@ -34,7 +34,8 @@ define [
|
||||
$scope.bibtexPreview.shouldShowDots = false
|
||||
$scope.$apply()
|
||||
$http.get(url)
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
$scope.bibtexPreview.loading = false
|
||||
$scope.bibtexPreview.error = false
|
||||
# show dots when payload is closs to cutoff
|
||||
@@ -46,7 +47,7 @@ define [
|
||||
finally
|
||||
$scope.bibtexPreview.data = data
|
||||
$timeout($scope.setHeight, 0)
|
||||
.catch (err) ->
|
||||
.catch () ->
|
||||
$scope.bibtexPreview.error = true
|
||||
$scope.bibtexPreview.loading = false
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ define [
|
||||
chat.state.loading = true
|
||||
return $http
|
||||
.get(url)
|
||||
.then (messages = [])->
|
||||
.then (response) ->
|
||||
messages = response.data ? []
|
||||
chat.state.loading = false
|
||||
if messages.length < MESSAGE_LIMIT
|
||||
chat.state.atEnd = true
|
||||
|
||||
@@ -23,12 +23,14 @@ define [
|
||||
$scope.state.inflight = true
|
||||
$scope.state.error = false
|
||||
cloneProject($scope.inputs.projectName)
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
window.location = "/project/#{data.project_id}"
|
||||
.catch (body, statusCode) ->
|
||||
.catch (response) ->
|
||||
{ data, status } = response
|
||||
$scope.state.inflight = false
|
||||
if statusCode == 400
|
||||
$scope.state.error = { message: body }
|
||||
if status == 400
|
||||
$scope.state.error = { message: data }
|
||||
else
|
||||
$scope.state.error = true
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ define [
|
||||
@$scope.history.loading = true
|
||||
@ide.$http
|
||||
.get(url)
|
||||
.then (data) =>
|
||||
.then (response) =>
|
||||
{ data } = response
|
||||
@_loadUpdates(data.updates)
|
||||
@$scope.history.nextBeforeTimestamp = data.nextBeforeTimestamp
|
||||
if !data.nextBeforeTimestamp?
|
||||
@@ -109,7 +110,8 @@ define [
|
||||
|
||||
@ide.$http
|
||||
.get(url)
|
||||
.then (data) =>
|
||||
.then (response) =>
|
||||
{ data } = response
|
||||
diff.loading = false
|
||||
{text, highlights} = @_parseDiff(data)
|
||||
diff.text = text
|
||||
|
||||
@@ -28,7 +28,8 @@ define [
|
||||
labels.loadProjectLabelsFromServer = () ->
|
||||
$http
|
||||
.get("/project/#{window.project_id}/labels")
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
if data.projectLabels
|
||||
for docId, docLabels of data.projectLabels
|
||||
state.documents[docId] = docLabels
|
||||
@@ -39,6 +40,5 @@ define [
|
||||
"/project/#{window.project_id}/doc/#{docId}/labels",
|
||||
{_csrf: window.csrfToken}
|
||||
)
|
||||
.then (data) ->
|
||||
|
||||
return labels
|
||||
|
||||
@@ -385,11 +385,13 @@ define [
|
||||
options.rootDocOverride_id = getRootDocOverride_id()
|
||||
|
||||
sendCompileRequest(options)
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
$scope.pdf.view = "pdf"
|
||||
$scope.pdf.compiling = false
|
||||
parseCompileResponse(data)
|
||||
.catch (err, status) ->
|
||||
.catch (response) ->
|
||||
{ data, status } = response
|
||||
if status == 429
|
||||
$scope.pdf.rateLimited = true
|
||||
$scope.pdf.compiling = false
|
||||
@@ -514,9 +516,11 @@ define [
|
||||
clsiserverid:ide.clsiServerId
|
||||
}
|
||||
})
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
deferred.resolve(data.pdf or [])
|
||||
.catch (error) ->
|
||||
.catch (response) ->
|
||||
error = response.data
|
||||
deferred.reject(error)
|
||||
|
||||
return deferred.promise
|
||||
@@ -559,12 +563,14 @@ define [
|
||||
clsiserverid:ide.clsiServerId
|
||||
}
|
||||
})
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
if data.code? and data.code.length > 0
|
||||
doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
|
||||
return if !doc?
|
||||
deferred.resolve({doc: doc, line: data.code[0].line})
|
||||
.catch (error) ->
|
||||
.catch (response) ->
|
||||
error = response.data
|
||||
deferred.reject(error)
|
||||
|
||||
return deferred.promise
|
||||
|
||||
@@ -188,7 +188,8 @@ define [
|
||||
|
||||
refreshRanges = () ->
|
||||
$http.get "/project/#{$scope.project_id}/ranges"
|
||||
.then (docs) ->
|
||||
.then (response) ->
|
||||
docs = response.data
|
||||
for doc in docs
|
||||
if !$scope.reviewPanel.overview.docsCollapsedState[doc.id]?
|
||||
$scope.reviewPanel.overview.docsCollapsedState[doc.id] = false
|
||||
@@ -438,7 +439,7 @@ define [
|
||||
thread.submitting = true
|
||||
$scope.$broadcast "comment:add", thread_id, offset, length
|
||||
$http.post("/project/#{$scope.project_id}/thread/#{thread_id}/messages", {content, _csrf: window.csrfToken})
|
||||
.catch (error) ->
|
||||
.catch () ->
|
||||
ide.showGenericMessageModal("Error submitting comment", "Sorry, there was a problem submitting your comment")
|
||||
$scope.$broadcast "editor:clearSelection"
|
||||
$timeout () ->
|
||||
@@ -458,7 +459,7 @@ define [
|
||||
thread_id = entry.thread_id
|
||||
content = entry.replyContent
|
||||
$http.post("/project/#{$scope.project_id}/thread/#{thread_id}/messages", {content, _csrf: window.csrfToken})
|
||||
.catch (error) ->
|
||||
.catch () ->
|
||||
ide.showGenericMessageModal("Error submitting comment", "Sorry, there was a problem submitting your comment")
|
||||
|
||||
trackingMetadata =
|
||||
@@ -598,7 +599,8 @@ define [
|
||||
_refreshingRangeUsers = true
|
||||
|
||||
$http.get "/project/#{$scope.project_id}/changes/users"
|
||||
.then (users) ->
|
||||
.then (response) ->
|
||||
users = response.data
|
||||
_refreshingRangeUsers = false
|
||||
$scope.users = {}
|
||||
# Always include ourself, since if we submit an op, we might need to display info
|
||||
@@ -619,7 +621,8 @@ define [
|
||||
_threadsLoaded = true
|
||||
$scope.reviewPanel.loadingThreads = true
|
||||
$http.get "/project/#{$scope.project_id}/threads"
|
||||
.then (threads) ->
|
||||
.then (response) ->
|
||||
threads = response.data
|
||||
$scope.reviewPanel.loadingThreads = false
|
||||
for thread_id, _ of $scope.reviewPanel.resolvedThreadIds
|
||||
delete $scope.reviewPanel.resolvedThreadIds[thread_id]
|
||||
|
||||
@@ -34,7 +34,8 @@ define [
|
||||
$scope.autocompleteContacts = []
|
||||
do loadAutocompleteUsers = () ->
|
||||
$http.get "/user/contacts"
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
$scope.autocompleteContacts = data.contacts or []
|
||||
for contact in $scope.autocompleteContacts
|
||||
if contact.type == "user"
|
||||
@@ -102,7 +103,8 @@ define [
|
||||
request = projectInvites.sendInvite(email, $scope.inputs.privileges)
|
||||
|
||||
request
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
if data.error
|
||||
$scope.state.error = true
|
||||
$scope.state.errorReason = "#{data.error}"
|
||||
|
||||
@@ -11,7 +11,8 @@ define [
|
||||
params:
|
||||
clsiserverid:ide.clsiServerId
|
||||
$http opts
|
||||
.then (data) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
$scope.status.loading = false
|
||||
$scope.data = data.texcount
|
||||
.catch () ->
|
||||
|
||||
@@ -9,7 +9,6 @@ define [
|
||||
"libs/fineuploader"
|
||||
"libs/angular-sanitize-1.2.17"
|
||||
"libs/angular-cookie"
|
||||
"libs/angular-cookies"
|
||||
"libs/passfield"
|
||||
"libs/sixpack"
|
||||
"libs/groove"
|
||||
|
||||
@@ -69,7 +69,8 @@ define [
|
||||
window.location = "/login"
|
||||
, 1000
|
||||
)
|
||||
.catch (data, status) ->
|
||||
.catch (response) ->
|
||||
{ data, status } = response
|
||||
$scope.state.inflight = false
|
||||
if status == 403
|
||||
$scope.state.invalidCredentials = true
|
||||
|
||||
@@ -8,8 +8,8 @@ define [
|
||||
newItems: 0
|
||||
|
||||
refreshAnnouncements = ->
|
||||
$http.get("/announcements").then (announcements) ->
|
||||
$scope.announcements = announcements
|
||||
$http.get("/announcements").then (response) ->
|
||||
$scope.announcements = response.data
|
||||
$scope.ui.newItems = _.filter(announcements, (announcement) -> !announcement.read).length
|
||||
|
||||
markAnnouncementsAsRead = ->
|
||||
|
||||
@@ -162,10 +162,10 @@ define [
|
||||
|
||||
|
||||
$http.post("/user/subscription/create", postData)
|
||||
.then (data, status, headers)->
|
||||
.then ()->
|
||||
event_tracking.sendMB "subscription-submission-success"
|
||||
window.location.href = "/user/subscription/thank-you"
|
||||
.catch (data, status, headers)->
|
||||
.catch ()->
|
||||
$scope.processing = false
|
||||
$scope.genericError = "Something went wrong processing the request"
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ define [
|
||||
headers:
|
||||
"X-Csrf-Token": window.csrfToken
|
||||
})
|
||||
.then (data) ->
|
||||
.then () ->
|
||||
notification.hide = true
|
||||
|
||||
App.controller "ProjectInviteNotificationController", ($scope, $http) ->
|
||||
|
||||
@@ -263,6 +263,7 @@ define [
|
||||
template: template
|
||||
})
|
||||
.then((data, status, headers, config) ->
|
||||
console.log data, status, headers, config
|
||||
$scope.projects.push {
|
||||
name: name
|
||||
_id: data.project_id
|
||||
|
||||
@@ -94,7 +94,8 @@ define [
|
||||
_csrf: window.csrfToken,
|
||||
name: name
|
||||
}
|
||||
.then (data, status, headers, config) ->
|
||||
.then (response) ->
|
||||
{ data } = response
|
||||
$scope.state.inflight = false
|
||||
$modalInstance.close(data)
|
||||
.catch () ->
|
||||
|
||||
@@ -16,19 +16,20 @@ define [
|
||||
$scope.cancelSubscription = ->
|
||||
$scope.inflight = true
|
||||
request = $http.post "/user/subscription/cancel", {_csrf:window.csrfToken}
|
||||
request.then (data, status)->
|
||||
request.then ()->
|
||||
$scope.inflight = false
|
||||
$scope.view = "groupSubscriptionInvite"
|
||||
request.catch (data, status)->
|
||||
request.catch ()->
|
||||
console.log "the request failed"
|
||||
|
||||
$scope.joinGroup = ->
|
||||
$scope.view = "requestSent"
|
||||
$scope.inflight = true
|
||||
request = $http.post "/user/subscription/#{group_subscription_id}/group/begin-join", {_csrf:window.csrfToken}
|
||||
request.then (data, status)->
|
||||
request.then (response)->
|
||||
{ status } = response
|
||||
$scope.inflight = false
|
||||
if status != 200 # assume request worked
|
||||
$scope.requestSent = false
|
||||
request.catch (data, status)->
|
||||
request.catch ()->
|
||||
console.log "the request failed"
|
||||
@@ -7,7 +7,8 @@ define [
|
||||
|
||||
App.controller "UserProfileController", ($scope, $modal, $http)->
|
||||
$scope.institutions = []
|
||||
$http.get("/user/personal_info").then (data)->
|
||||
$http.get("/user/personal_info").then (response)->
|
||||
{ data } = response
|
||||
$scope.userInfoForm =
|
||||
first_name: data.first_name || ""
|
||||
last_name: data.last_name || ""
|
||||
@@ -43,8 +44,8 @@ define [
|
||||
|
||||
sendUpdate = ->
|
||||
request = $http.post "/user/settings", $scope.userInfoForm
|
||||
request.then (data, status)->
|
||||
request.catch (data, status)->
|
||||
request.then ()->
|
||||
request.catch ()->
|
||||
console.log "the request failed"
|
||||
|
||||
$scope.updateInstitutionsList = (inputVal)->
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
angular.module('mvdSixpack', ['ngCookies'])
|
||||
angular.module('mvdSixpack', [ 'ipCookie' ])
|
||||
.provider('sixpack', function() {
|
||||
var $body
|
||||
, _tests = []
|
||||
@@ -45,18 +45,19 @@
|
||||
angular.extend(_opts, options || {});
|
||||
}
|
||||
|
||||
this.$get = ['$cookies','$timeout', '$log', function($cookies, $timeout, $log) {
|
||||
this.$get = ['ipCookie','$timeout', '$log', function(ipCookie, $timeout, $log) {
|
||||
var _cookiePrefix = 'sixpack-'
|
||||
, _session
|
||||
, _clientId;
|
||||
|
||||
var _getOrInitSession = function () {
|
||||
if (!_session) {
|
||||
if (_clientId = $cookies[_cookiePrefix + 'clientId']) {
|
||||
if (_clientId = ipCookie(_cookiePrefix + 'clientId')) {
|
||||
_session = new sp.Session({client_id:_clientId, base_url:_opts.baseUrl});
|
||||
} else {
|
||||
_session = new sp.Session({client_id:_opts.client_id, base_url:_opts.baseUrl});
|
||||
$cookies[_cookiePrefix + 'clientId'] = _clientId = _session.client_id;
|
||||
_clientId = _session.client_id;
|
||||
ipCookie(_cookiePrefix + 'clientId', _clientId);
|
||||
}
|
||||
if (_opts.debug) {
|
||||
$log.debug('[sixpack] Initialized session with clientId', _clientId, 'and base url', _opts.baseUrl);
|
||||
|
||||
Reference in New Issue
Block a user