Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
32dfa801
Commit
32dfa801
authored
Mar 17, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves poll inside GL
parent
bb1620aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
app/assets/javascripts/lib/utils/poll.js
app/assets/javascripts/lib/utils/poll.js
+54
-0
No files found.
app/assets/javascripts/lib/utils/poll.js
0 → 100644
View file @
32dfa801
import
Vue
from
'
vue
'
;
import
VueResource
from
'
vue-resource
'
;
import
httpStatusCodes
from
'
./http_status
'
;
Vue
.
use
(
VueResource
);
/**
* Polling utility for handling realtime updates with Vue.Resource get method.
*
* @example
* new poll({
* url: 'endopoint',
* data: {},
* successCallback: () => {}
* errorCallback: () => {}
* }).makeRequest();
*
*
* 1. Checks for response and headers before start polling
* 2. Interval is provided by `X-Poll-Interval` header.
* 3. If `X-Poll-Interval` is -1, we stop polling
* 4. If HTTP response is 200, we poll.
* 5. If HTTP response is different from 200, we stop polling.
*
*/
export
default
class
poll
{
constructor
(
options
)
{
this
.
options
=
options
||
{};
this
.
intervalHeader
=
'
POLL-INTERVAL
'
;
}
checkConditions
(
response
)
{
const
headers
=
gl
.
utils
.
normalizeHeaders
(
response
.
headers
);
const
pollInterval
=
headers
[
this
.
intervalHeader
];
if
(
pollInterval
>
0
&&
response
.
status
===
httpStatusCodes
.
OK
)
{
this
.
options
.
successCallback
(
response
);
setTimeout
(()
=>
{
this
.
makeRequest
()
.
then
(
this
.
checkConditions
)
.
catch
(
error
=>
this
.
options
.
errorCallback
(
error
));
},
pollInterval
);
}
else
{
this
.
options
.
successCallback
(
response
);
}
}
makeRequest
()
{
return
Vue
.
http
.
get
(
this
.
options
.
url
,
this
.
options
.
data
)
.
then
(
this
.
checkConditions
)
.
catch
(
error
=>
this
.
options
.
errorCallback
(
error
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment