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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4158342b
Commit
4158342b
authored
May 12, 2017
by
Filipa Lacerda
Committed by
Z.J. van de Weg
May 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds polling function to environments table
Adds missing eventhub to folder table
parent
ebede2b3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
175 additions
and
55 deletions
+175
-55
app/assets/javascripts/environments/components/environment.vue
...ssets/javascripts/environments/components/environment.vue
+69
-26
app/assets/javascripts/environments/folder/environments_folder_view.vue
...ascripts/environments/folder/environments_folder_view.vue
+72
-28
app/assets/javascripts/environments/mixins/environments_mixin.js
...ets/javascripts/environments/mixins/environments_mixin.js
+17
-0
app/assets/javascripts/environments/services/environments_service.js
...javascripts/environments/services/environments_service.js
+2
-1
app/assets/javascripts/environments/stores/environments_store.js
...ets/javascripts/environments/stores/environments_store.js
+6
-0
spec/javascripts/environments/environments_store_spec.js
spec/javascripts/environments/environments_store_spec.js
+9
-0
No files found.
app/assets/javascripts/environments/components/environment.vue
View file @
4158342b
<
script
>
/* global Flash */
import
Visibility
from
'
visibilityjs
'
;
import
EnvironmentsService
from
'
../services/environments_service
'
;
import
environmentTable
from
'
./environments_table.vue
'
;
import
EnvironmentsStore
from
'
../stores/environments_store
'
;
...
...
@@ -7,6 +8,8 @@ import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import
tablePagination
from
'
../../vue_shared/components/table_pagination.vue
'
;
import
'
../../lib/utils/common_utils
'
;
import
eventHub
from
'
../event_hub
'
;
import
Poll
from
'
../../lib/utils/poll
'
;
import
environmentsMixin
from
'
../mixins/environments_mixin
'
;
export
default
{
...
...
@@ -16,6 +19,10 @@ export default {
loadingIcon
,
},
mixins
:
[
environmentsMixin
,
],
data
()
{
const
environmentsData
=
document
.
querySelector
(
'
#environments-list-view
'
).
dataset
;
const
store
=
new
EnvironmentsStore
();
...
...
@@ -35,6 +42,7 @@ export default {
projectStoppedEnvironmentsPath
:
environmentsData
.
projectStoppedEnvironmentsPath
,
newEnvironmentPath
:
environmentsData
.
newEnvironmentPath
,
helpPagePath
:
environmentsData
.
helpPagePath
,
isMakingRequest
:
false
,
// Pagination Properties,
paginationInformation
:
{},
...
...
@@ -65,17 +73,43 @@ export default {
* Toggles loading property.
*/
created
()
{
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
)
||
this
.
visibility
;
const
page
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
this
.
service
=
new
EnvironmentsService
(
this
.
endpoint
);
this
.
fetchEnvironments
();
const
poll
=
new
Poll
({
resource
:
this
.
service
,
method
:
'
get
'
,
data
:
{
scope
,
page
},
successCallback
:
this
.
successCallback
,
errorCallback
:
this
.
errorCallback
,
notificationCallback
:
(
isMakingRequest
)
=>
{
this
.
isMakingRequest
=
isMakingRequest
;
// We need to verify if any folder is open to also fecth it
this
.
openFolders
=
this
.
store
.
getOpenFolders
();
},
});
if
(
!
Visibility
.
hidden
())
{
this
.
isLoading
=
true
;
poll
.
makeRequest
();
}
Visibility
.
change
(()
=>
{
if
(
!
Visibility
.
hidden
())
{
poll
.
restart
();
}
else
{
poll
.
stop
();
}
});
eventHub
.
$on
(
'
refreshEnvironments
'
,
this
.
fetchEnvironments
);
eventHub
.
$on
(
'
toggleFolder
'
,
this
.
toggleFolder
);
eventHub
.
$on
(
'
postAction
'
,
this
.
postAction
);
},
beforeDestroyed
()
{
eventHub
.
$off
(
'
refreshEnvironments
'
);
eventHub
.
$off
(
'
toggleFolder
'
);
eventHub
.
$off
(
'
postAction
'
);
},
...
...
@@ -104,29 +138,13 @@ export default {
fetchEnvironments
()
{
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
)
||
this
.
visibility
;
const
page
Number
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
const
page
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
this
.
isLoading
=
true
;
return
this
.
service
.
get
(
scope
,
pageNumber
)
.
then
(
resp
=>
({
headers
:
resp
.
headers
,
body
:
resp
.
json
(),
}))
.
then
((
response
)
=>
{
this
.
store
.
storeAvailableCount
(
response
.
body
.
available_count
);
this
.
store
.
storeStoppedCount
(
response
.
body
.
stopped_count
);
this
.
store
.
storeEnvironments
(
response
.
body
.
environments
);
this
.
store
.
setPagination
(
response
.
headers
);
})
.
then
(()
=>
{
this
.
isLoading
=
false
;
})
.
catch
(()
=>
{
this
.
isLoading
=
false
;
// eslint-disable-next-line no-new
new
Flash
(
'
An error occurred while fetching the environments.
'
);
});
return
this
.
service
.
get
({
scope
,
page
})
.
then
(
this
.
successCallback
)
.
catch
(
this
.
errorCallback
);
},
fetchChildEnvironments
(
folder
,
folderUrl
)
{
...
...
@@ -146,9 +164,34 @@ export default {
},
postAction
(
endpoint
)
{
if
(
!
this
.
isMakingRequest
)
{
this
.
isLoading
=
true
;
this
.
service
.
postAction
(
endpoint
)
.
then
(()
=>
this
.
fetchEnvironments
())
.
catch
(()
=>
new
Flash
(
'
An error occured while making the request.
'
));
}
},
successCallback
(
resp
)
{
this
.
saveData
(
resp
);
// If folders are open while polling we need to open them again
if
(
this
.
openFolders
.
length
)
{
this
.
openFolders
.
map
((
folder
)
=>
{
// TODO - Move this to the backend
const
folderUrl
=
`
${
window
.
location
.
pathname
}
/folders/
${
folder
.
folderName
}
`
;
this
.
store
.
updateFolder
(
folder
,
'
isOpen
'
,
true
);
return
this
.
fetchChildEnvironments
(
folder
,
folderUrl
);
});
}
},
errorCallback
()
{
this
.
isLoading
=
false
;
// eslint-disable-next-line no-new
new
Flash
(
'
An error occurred while fetching the environments.
'
);
},
},
};
...
...
app/assets/javascripts/environments/folder/environments_folder_view.vue
View file @
4158342b
<
script
>
/* global Flash */
import
Visibility
from
'
visibilityjs
'
;
import
EnvironmentsService
from
'
../services/environments_service
'
;
import
environmentTable
from
'
../components/environments_table.vue
'
;
import
EnvironmentsStore
from
'
../stores/environments_store
'
;
import
loadingIcon
from
'
../../vue_shared/components/loading_icon.vue
'
;
import
tablePagination
from
'
../../vue_shared/components/table_pagination.vue
'
;
import
Poll
from
'
../../lib/utils/poll
'
;
import
eventHub
from
'
../event_hub
'
;
import
environmentsMixin
from
'
../mixins/environments_mixin
'
;
import
'
../../lib/utils/common_utils
'
;
import
'
../../vue_shared/vue_resource_interceptor
'
;
export
default
{
components
:
{
...
...
@@ -15,6 +18,10 @@ export default {
loadingIcon
,
},
mixins
:
[
environmentsMixin
,
],
data
()
{
const
environmentsData
=
document
.
querySelector
(
'
#environments-folder-list-view
'
).
dataset
;
const
store
=
new
EnvironmentsStore
();
...
...
@@ -76,33 +83,39 @@ export default {
*/
created
()
{
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
)
||
this
.
visibility
;
const
pageNumber
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
const
endpoint
=
`
${
this
.
endpoint
}
?scope=
${
scope
}
&page=
${
pageNumber
}
`
;
this
.
service
=
new
EnvironmentsService
(
endpoint
);
const
page
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
this
.
service
=
new
EnvironmentsService
(
this
.
endpoint
);
const
poll
=
new
Poll
({
resource
:
this
.
service
,
method
:
'
get
'
,
data
:
{
scope
,
page
},
successCallback
:
this
.
successCallback
,
errorCallback
:
this
.
errorCallback
,
notificationCallback
:
(
isMakingRequest
)
=>
{
this
.
isMakingRequest
=
isMakingRequest
;
},
});
if
(
!
Visibility
.
hidden
())
{
this
.
isLoading
=
true
;
return
this
.
service
.
get
()
.
then
(
resp
=>
({
headers
:
resp
.
headers
,
body
:
resp
.
json
(),
}))
.
then
((
response
)
=>
{
this
.
store
.
storeAvailableCount
(
response
.
body
.
available_count
);
this
.
store
.
storeStoppedCount
(
response
.
body
.
stopped_count
);
this
.
store
.
storeEnvironments
(
response
.
body
.
environments
);
this
.
store
.
setPagination
(
response
.
headers
);
})
.
then
(()
=>
{
this
.
isLoading
=
false
;
})
.
catch
(()
=>
{
this
.
isLoading
=
false
;
// eslint-disable-next-line no-new
new
Flash
(
'
An error occurred while fetching the environments.
'
,
'
alert
'
);
poll
.
makeRequest
();
}
Visibility
.
change
(()
=>
{
if
(
!
Visibility
.
hidden
())
{
poll
.
restart
();
}
else
{
poll
.
stop
();
}
});
eventHub
.
$on
(
'
postAction
'
,
this
.
postAction
);
},
beforeDestroyed
()
{
eventHub
.
$off
(
'
postAction
'
);
},
methods
:
{
...
...
@@ -117,6 +130,37 @@ export default {
gl
.
utils
.
visitUrl
(
param
);
return
param
;
},
fetchEnvironments
()
{
const
scope
=
gl
.
utils
.
getParameterByName
(
'
scope
'
)
||
this
.
visibility
;
const
page
=
gl
.
utils
.
getParameterByName
(
'
page
'
)
||
this
.
pageNumber
;
this
.
isLoading
=
true
;
return
this
.
service
.
get
({
scope
,
page
})
.
then
(
this
.
successCallback
)
.
catch
(
this
.
errorCallback
);
},
successCallback
(
resp
)
{
this
.
saveData
(
resp
);
},
errorCallback
()
{
this
.
isLoading
=
false
;
// eslint-disable-next-line no-new
new
Flash
(
'
An error occurred while fetching the environments.
'
);
},
postAction
(
endpoint
)
{
if
(
!
this
.
isMakingRequest
)
{
this
.
isLoading
=
true
;
this
.
service
.
postAction
(
endpoint
)
.
then
(()
=>
this
.
fetchEnvironments
())
.
catch
(()
=>
new
Flash
(
'
An error occured while making the request.
'
));
}
},
},
};
</
script
>
...
...
app/assets/javascripts/environments/mixins/environments_mixin.js
0 → 100644
View file @
4158342b
export
default
{
methods
:
{
saveData
(
resp
)
{
const
response
=
{
headers
:
resp
.
headers
,
body
:
resp
.
json
(),
};
this
.
isLoading
=
false
;
this
.
store
.
storeAvailableCount
(
response
.
body
.
available_count
);
this
.
store
.
storeStoppedCount
(
response
.
body
.
stopped_count
);
this
.
store
.
storeEnvironments
(
response
.
body
.
environments
);
this
.
store
.
setPagination
(
response
.
headers
);
},
},
};
app/assets/javascripts/environments/services/environments_service.js
View file @
4158342b
...
...
@@ -10,7 +10,8 @@ export default class EnvironmentsService {
this
.
folderResults
=
3
;
}
get
(
scope
,
page
)
{
get
(
options
=
{})
{
const
{
scope
,
page
}
=
options
;
return
this
.
environments
.
get
({
scope
,
page
});
}
...
...
app/assets/javascripts/environments/stores/environments_store.js
View file @
4158342b
...
...
@@ -153,4 +153,10 @@ export default class EnvironmentsStore {
return
updatedEnvironments
;
}
getOpenFolders
()
{
const
environments
=
this
.
state
.
environments
;
return
environments
.
filter
(
env
=>
env
.
isFolder
&&
env
.
isOpen
);
}
}
spec/javascripts/environments/environments_store_spec.js
View file @
4158342b
...
...
@@ -123,4 +123,13 @@ describe('Store', () => {
expect
(
store
.
state
.
paginationInformation
).
toEqual
(
expectedResult
);
});
});
describe
(
'
getOpenFolders
'
,
()
=>
{
it
(
'
should return open folder
'
,
()
=>
{
store
.
storeEnvironments
(
serverData
);
store
.
toggleFolder
(
store
.
state
.
environments
[
1
]);
expect
(
store
.
getOpenFolders
()[
0
]).
toEqual
(
store
.
state
.
environments
[
1
]);
});
});
});
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