BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
60f6b596
Commit
60f6b596
authored
Aug 02, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ci skip] Use eTag polling with Poll utility to allow stoping polling when visibily changes
parent
6d50b752
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
38 deletions
+53
-38
issue_notes_app.vue
app/assets/javascripts/notes/components/issue_notes_app.vue
+2
-16
issue_notes_service.js
app/assets/javascripts/notes/services/issue_notes_service.js
+2
-1
actions.js
app/assets/javascripts/notes/stores/actions.js
+49
-21
No files found.
app/assets/javascripts/notes/components/issue_notes_app.vue
View file @
60f6b596
...
...
@@ -88,26 +88,12 @@
this
.
checkLocationHash
();
});
})
.
catch
((
error
)
=>
{
console
.
log
(
error
)
Flash
(
'Something went wrong while fetching issue comments. Please try again.'
)
});
.
catch
((
error
)
=>
Flash
(
'Something went wrong while fetching issue comments. Please try again.'
));
},
initPolling
()
{
this
.
setLastFetchedAt
(
this
.
getNotesDataByProp
(
'lastFetchedAt'
));
// FIXME: @fatihacet Implement real polling mechanism
// TODO: FILIPA: DEAL WITH THIS
setInterval
(()
=>
{
this
.
poll
()
.
then
((
res
)
=>
{
this
.
setLastFetchedAt
(
res
.
lastFetchedAt
);
})
.
catch
((
error
)
=>
{
console
.
log
(
error
)
Flash
(
'Something went wrong while fetching latest comments.'
)
}
);
},
15000
);
this
.
poll
();
},
bindEventHubListeners
()
{
this
.
$el
.
parentElement
.
addEventListener
(
'toggleAward'
,
(
event
)
=>
{
...
...
app/assets/javascripts/notes/services/issue_notes_service.js
View file @
60f6b596
...
...
@@ -19,7 +19,8 @@ export default {
createNewNote
(
endpoint
,
data
)
{
return
Vue
.
http
.
post
(
endpoint
,
data
,
{
emulateJSON
:
true
});
},
poll
(
endpoint
,
lastFetchedAt
)
{
poll
(
data
=
{})
{
const
{
endpoint
,
lastFetchedAt
}
=
data
;
const
options
=
{
headers
:
{
'X-Last-Fetched-At'
:
lastFetchedAt
,
...
...
app/assets/javascripts/notes/stores/actions.js
View file @
60f6b596
/* global Flash */
import
Visibility
from
'visibilityjs'
;
import
Poll
from
'../../lib/utils/poll'
;
import
*
as
types
from
'./mutation_types'
;
import
*
as
utils
from
'./utils'
;
import
*
as
constants
from
'../constants'
;
...
...
@@ -131,31 +132,58 @@ export const saveNote = ({ commit, dispatch }, noteData) => {
});
};
export
const
poll
=
({
commit
,
state
,
getters
})
=>
service
.
poll
(
state
.
notesData
.
notesPath
,
state
.
lastFetchedAt
)
.
then
(
res
=>
res
.
json
())
.
then
((
res
)
=>
{
if
(
res
.
notes
.
length
)
{
const
{
notesById
}
=
getters
;
res
.
notes
.
forEach
((
note
)
=>
{
if
(
notesById
[
note
.
id
])
{
commit
(
types
.
UPDATE_NOTE
,
note
);
}
else
if
(
note
.
type
===
constants
.
DISCUSSION_NOTE
)
{
const
discussion
=
utils
.
findNoteObjectById
(
state
.
notes
,
note
.
discussion_id
);
if
(
discussion
)
{
commit
(
types
.
ADD_NEW_REPLY_TO_DISCUSSION
,
note
);
}
else
{
commit
(
types
.
ADD_NEW_NOTE
,
note
);
}
const
pollSuccessCallBack
=
(
resp
,
commit
,
state
,
getters
)
=>
{
if
(
resp
.
notes
.
length
)
{
const
{
notesById
}
=
getters
;
resp
.
notes
.
forEach
((
note
)
=>
{
if
(
notesById
[
note
.
id
])
{
commit
(
types
.
UPDATE_NOTE
,
note
);
}
else
if
(
note
.
type
===
constants
.
DISCUSSION_NOTE
)
{
const
discussion
=
utils
.
findNoteObjectById
(
state
.
notes
,
note
.
discussion_id
);
if
(
discussion
)
{
commit
(
types
.
ADD_NEW_REPLY_TO_DISCUSSION
,
note
);
}
else
{
commit
(
types
.
ADD_NEW_NOTE
,
note
);
}
});
}
else
{
commit
(
types
.
ADD_NEW_NOTE
,
note
);
}
});
}
commit
(
types
.
SET_LAST_FETCHED_AT
,
resp
.
lastFetchedAt
);
return
resp
;
};
export
const
poll
=
({
commit
,
state
,
getters
})
=>
{
const
requestData
=
{
endpoint
:
state
.
notesData
.
notesPath
,
lastFetchedAt
:
state
.
lastFetchedAt
};
const
eTagPoll
=
new
Poll
({
resource
:
service
,
method
:
'poll'
,
data
:
requestData
,
successCallback
:
resp
=>
resp
.
json
()
.
then
(
data
=>
pollSuccessCallBack
(
data
,
commit
,
state
,
getters
)),
errorCallback
:
()
=>
Flash
(
'Something went wrong while fetching latest comments.'
),
});
if
(
!
Visibility
.
hidden
())
{
eTagPoll
.
makeRequest
();
}
else
{
this
.
service
.
poll
(
requestData
);
}
Visibility
.
change
(()
=>
{
if
(
!
Visibility
.
hidden
())
{
eTagPoll
.
restart
();
}
else
{
eTagPoll
.
stop
();
}
return
res
;
});
};
export
const
toggleAward
=
({
commit
,
getters
,
dispatch
},
data
)
=>
{
const
{
endpoint
,
awardName
,
noteId
,
skipMutalityCheck
}
=
data
;
...
...
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