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
12f107e1
Commit
12f107e1
authored
May 23, 2017
by
winh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AjaxCache in Droplab AjaxFilter
parent
e15aee2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
36 deletions
+11
-36
app/assets/javascripts/droplab/plugins/ajax_filter.js
app/assets/javascripts/droplab/plugins/ajax_filter.js
+11
-36
No files found.
app/assets/javascripts/droplab/plugins/ajax_filter.js
View file @
12f107e1
/* eslint-disable */
import
AjaxCache
from
'
../../lib/utils/ajax_cache
'
;
const
AjaxFilter
=
{
init
:
function
(
hook
)
{
...
...
@@ -58,50 +59,24 @@ const AjaxFilter = {
this
.
loading
=
true
;
var
params
=
config
.
params
||
{};
params
[
config
.
searchKey
]
=
searchValue
;
var
self
=
this
;
self
.
cache
=
self
.
cache
||
{};
var
url
=
config
.
endpoint
+
this
.
buildParams
(
params
);
var
urlCachedData
=
self
.
cache
[
url
];
if
(
urlCachedData
)
{
self
.
_loadData
(
urlCachedData
,
config
,
self
);
}
else
{
this
.
_loadUrlData
(
url
)
.
then
(
function
(
data
)
{
self
.
_loadData
(
data
,
config
,
self
);
},
config
.
onError
).
catch
(
config
.
onError
);
}
return
AjaxCache
.
retrieve
(
url
)
.
then
((
data
)
=>
{
this
.
_loadData
(
data
,
config
);
})
.
catch
(
config
.
onError
);
},
_loadUrlData
:
function
_loadUrlData
(
url
)
{
var
self
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
xhr
=
new
XMLHttpRequest
;
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
XMLHttpRequest
.
DONE
)
{
if
(
xhr
.
status
===
200
)
{
var
data
=
JSON
.
parse
(
xhr
.
responseText
);
self
.
cache
[
url
]
=
data
;
return
resolve
(
data
);
}
else
{
return
reject
([
xhr
.
responseText
,
xhr
.
status
]);
}
}
};
xhr
.
send
();
});
},
_loadData
:
function
_loadData
(
data
,
config
,
self
)
{
const
list
=
self
.
hook
.
list
;
_loadData
(
data
,
config
)
{
const
list
=
this
.
hook
.
list
;
if
(
config
.
loadingTemplate
&&
list
.
data
===
undefined
||
list
.
data
.
length
===
0
)
{
const
dataLoadingTemplate
=
list
.
list
.
querySelector
(
'
[data-loading-template]
'
);
if
(
dataLoadingTemplate
)
{
dataLoadingTemplate
.
outerHTML
=
self
.
listTemplate
;
dataLoadingTemplate
.
outerHTML
=
this
.
listTemplate
;
}
}
if
(
!
self
.
destroyed
)
{
if
(
!
this
.
destroyed
)
{
var
hookListChildren
=
list
.
list
.
children
;
var
onlyDynamicList
=
hookListChildren
.
length
===
1
&&
hookListChildren
[
0
].
hasAttribute
(
'
data-dynamic
'
);
if
(
onlyDynamicList
&&
data
.
length
===
0
)
{
...
...
@@ -109,7 +84,7 @@ const AjaxFilter = {
}
list
.
setData
.
call
(
list
,
data
);
}
self
.
notLoading
();
this
.
notLoading
();
list
.
currentIndex
=
0
;
},
...
...
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