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
Boxiang Sun
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
Show 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 */
/* eslint-disable */
import
AjaxCache
from
'
../../lib/utils/ajax_cache
'
;
const
AjaxFilter
=
{
const
AjaxFilter
=
{
init
:
function
(
hook
)
{
init
:
function
(
hook
)
{
...
@@ -58,50 +59,24 @@ const AjaxFilter = {
...
@@ -58,50 +59,24 @@ const AjaxFilter = {
this
.
loading
=
true
;
this
.
loading
=
true
;
var
params
=
config
.
params
||
{};
var
params
=
config
.
params
||
{};
params
[
config
.
searchKey
]
=
searchValue
;
params
[
config
.
searchKey
]
=
searchValue
;
var
self
=
this
;
self
.
cache
=
self
.
cache
||
{};
var
url
=
config
.
endpoint
+
this
.
buildParams
(
params
);
var
url
=
config
.
endpoint
+
this
.
buildParams
(
params
);
var
urlCachedData
=
self
.
cache
[
url
];
return
AjaxCache
.
retrieve
(
url
)
if
(
urlCachedData
)
{
.
then
((
data
)
=>
{
self
.
_loadData
(
urlCachedData
,
config
,
self
);
this
.
_loadData
(
data
,
config
);
}
else
{
})
this
.
_loadUrlData
(
url
)
.
catch
(
config
.
onError
);
.
then
(
function
(
data
)
{
self
.
_loadData
(
data
,
config
,
self
);
},
config
.
onError
).
catch
(
config
.
onError
);
}
},
},
_loadUrlData
:
function
_loadUrlData
(
url
)
{
_loadData
(
data
,
config
)
{
var
self
=
this
;
const
list
=
this
.
hook
.
list
;
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
;
if
(
config
.
loadingTemplate
&&
list
.
data
===
undefined
||
if
(
config
.
loadingTemplate
&&
list
.
data
===
undefined
||
list
.
data
.
length
===
0
)
{
list
.
data
.
length
===
0
)
{
const
dataLoadingTemplate
=
list
.
list
.
querySelector
(
'
[data-loading-template]
'
);
const
dataLoadingTemplate
=
list
.
list
.
querySelector
(
'
[data-loading-template]
'
);
if
(
dataLoadingTemplate
)
{
if
(
dataLoadingTemplate
)
{
dataLoadingTemplate
.
outerHTML
=
self
.
listTemplate
;
dataLoadingTemplate
.
outerHTML
=
this
.
listTemplate
;
}
}
}
}
if
(
!
self
.
destroyed
)
{
if
(
!
this
.
destroyed
)
{
var
hookListChildren
=
list
.
list
.
children
;
var
hookListChildren
=
list
.
list
.
children
;
var
onlyDynamicList
=
hookListChildren
.
length
===
1
&&
hookListChildren
[
0
].
hasAttribute
(
'
data-dynamic
'
);
var
onlyDynamicList
=
hookListChildren
.
length
===
1
&&
hookListChildren
[
0
].
hasAttribute
(
'
data-dynamic
'
);
if
(
onlyDynamicList
&&
data
.
length
===
0
)
{
if
(
onlyDynamicList
&&
data
.
length
===
0
)
{
...
@@ -109,7 +84,7 @@ const AjaxFilter = {
...
@@ -109,7 +84,7 @@ const AjaxFilter = {
}
}
list
.
setData
.
call
(
list
,
data
);
list
.
setData
.
call
(
list
,
data
);
}
}
self
.
notLoading
();
this
.
notLoading
();
list
.
currentIndex
=
0
;
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