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
54fe9a1e
Commit
54fe9a1e
authored
May 24, 2017
by
Clement Ho
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'winh-ajax-filter-cache' into 'master'
Use AjaxCache in Droplab AjaxFilter See merge request !11643
parents
c846a832
12f107e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
36 deletions
+11
-36
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 @
54fe9a1e
/* 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