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
f42397d1
Commit
f42397d1
authored
Feb 27, 2018
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add persistent flash messages
parent
84e01b3e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
73 additions
and
9 deletions
+73
-9
app/assets/javascripts/lib/utils/flash_queue.js
app/assets/javascripts/lib/utils/flash_queue.js
+46
-0
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+2
-0
app/assets/javascripts/pages/milestones/shared/components/promote_milestone_modal.vue
.../milestones/shared/components/promote_milestone_modal.vue
+5
-1
app/assets/javascripts/pages/projects/labels/components/promote_label_modal.vue
.../pages/projects/labels/components/promote_label_modal.vue
+5
-1
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+2
-1
app/controllers/projects/milestones_controller.rb
app/controllers/projects/milestones_controller.rb
+3
-2
app/helpers/flash_helper.rb
app/helpers/flash_helper.rb
+8
-0
spec/controllers/projects/labels_controller_spec.rb
spec/controllers/projects/labels_controller_spec.rb
+1
-1
spec/controllers/projects/milestones_controller_spec.rb
spec/controllers/projects/milestones_controller_spec.rb
+1
-3
No files found.
app/assets/javascripts/lib/utils/flash_queue.js
0 → 100644
View file @
f42397d1
import
_
from
'
underscore
'
;
import
createFlash
from
'
~/flash
'
;
import
AccessorUtilities
from
'
~/lib/utils/accessor
'
;
const
FLASH_QUEUE_KEY
=
'
flash-key
'
;
export
function
popFlashMessage
()
{
const
page
=
$
(
'
body
'
).
attr
(
'
data-page
'
);
let
savedFlashMessages
;
let
returnVal
=
false
;
if
(
!
page
)
{
return
returnVal
;
}
if
(
AccessorUtilities
.
isLocalStorageAccessSafe
())
{
savedFlashMessages
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
FLASH_QUEUE_KEY
));
const
queuedMessage
=
_
.
findWhere
(
savedFlashMessages
,
{
bodyData
:
page
});
if
(
queuedMessage
)
{
const
queuedMessageIndex
=
_
.
findIndex
(
savedFlashMessages
,
{
bodyData
:
page
});
createFlash
(
queuedMessage
.
message
,
queuedMessage
.
type
);
savedFlashMessages
.
splice
(
queuedMessageIndex
,
1
);
window
.
localStorage
.
setItem
(
FLASH_QUEUE_KEY
,
JSON
.
stringify
(
savedFlashMessages
));
}
returnVal
=
true
;
}
return
returnVal
;
}
export
function
saveFlashMessage
(
bodyData
,
message
,
type
)
{
let
savedFlashMessages
;
if
(
AccessorUtilities
.
isLocalStorageAccessSafe
())
{
savedFlashMessages
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
FLASH_QUEUE_KEY
));
if
(
!
savedFlashMessages
)
{
savedFlashMessages
=
[];
}
savedFlashMessages
.
push
({
bodyData
,
message
,
type
,
});
window
.
localStorage
.
setItem
(
FLASH_QUEUE_KEY
,
JSON
.
stringify
(
savedFlashMessages
));
}
}
app/assets/javascripts/main.js
View file @
f42397d1
...
...
@@ -33,6 +33,7 @@ import './milestone_select';
import
'
./projects_dropdown
'
;
import
'
./render_gfm
'
;
import
initBreadcrumbs
from
'
./breadcrumb
'
;
import
{
popFlashMessage
}
from
'
./lib/utils/flash_queue
'
;
import
initDispatcher
from
'
./dispatcher
'
;
...
...
@@ -262,4 +263,5 @@ document.addEventListener('DOMContentLoaded', () => {
}
initDispatcher
();
popFlashMessage
();
});
app/assets/javascripts/pages/milestones/shared/components/promote_milestone_modal.vue
View file @
f42397d1
<
script
>
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
createFlash
from
'
~/flash
'
;
import
{
saveFlashMessage
}
from
'
~/lib/utils/flash_queue
'
;
import
GlModal
from
'
~/vue_shared/components/gl_modal.vue
'
;
import
{
redirectTo
}
from
'
~/lib/utils/url_utility
'
;
import
{
s__
,
sprintf
}
from
'
~/locale
'
;
...
...
@@ -36,7 +37,10 @@
return
axios
.
post
(
this
.
url
)
.
then
((
response
)
=>
{
eventHub
.
$emit
(
'
promoteMilestoneModal.requestFinished
'
,
{
milestoneUrl
:
this
.
url
,
successful
:
true
});
redirectTo
(
response
.
request
.
responseURL
);
const
responseURL
=
new
URL
(
response
.
request
.
responseURL
);
const
bodyData
=
responseURL
.
searchParams
.
get
(
'
body_data
'
);
saveFlashMessage
(
bodyData
,
`
${
this
.
milestoneTitle
}
promoted to group milestone`
,
'
notice
'
);
redirectTo
(
`
${
responseURL
.
protocol
}
//
${
responseURL
.
host
}${
responseURL
.
pathname
}
`
);
})
.
catch
((
error
)
=>
{
eventHub
.
$emit
(
'
promoteMilestoneModal.requestFinished
'
,
{
milestoneUrl
:
this
.
url
,
successful
:
false
});
...
...
app/assets/javascripts/pages/projects/labels/components/promote_label_modal.vue
View file @
f42397d1
<
script
>
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
saveFlashMessage
}
from
'
~/lib/utils/flash_queue
'
;
import
createFlash
from
'
~/flash
'
;
import
GlModal
from
'
~/vue_shared/components/gl_modal.vue
'
;
import
{
redirectTo
}
from
'
~/lib/utils/url_utility
'
;
...
...
@@ -50,7 +51,10 @@
return
axios
.
post
(
this
.
url
)
.
then
((
response
)
=>
{
eventHub
.
$emit
(
'
promoteLabelModal.requestFinished
'
,
{
labelUrl
:
this
.
url
,
successful
:
true
});
redirectTo
(
response
.
request
.
responseURL
);
const
responseURL
=
new
URL
(
response
.
request
.
responseURL
);
const
bodyData
=
responseURL
.
searchParams
.
get
(
'
body_data
'
);
saveFlashMessage
(
bodyData
,
`
${
this
.
labelTitle
}
promoted to group label`
,
'
notice
'
);
redirectTo
(
`
${
responseURL
.
protocol
}
//
${
responseURL
.
host
}${
responseURL
.
pathname
}
`
);
})
.
catch
((
error
)
=>
{
eventHub
.
$emit
(
'
promoteLabelModal.requestFinished
'
,
{
labelUrl
:
this
.
url
,
successful
:
false
});
...
...
app/controllers/projects/labels_controller.rb
View file @
f42397d1
class
Projects::LabelsController
<
Projects
::
ApplicationController
include
ToggleSubscriptionAction
include
FlashHelper
before_action
:check_issuables_available!
before_action
:label
,
only:
[
:edit
,
:update
,
:destroy
,
:promote
]
...
...
@@ -114,7 +115,7 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to
do
|
format
|
format
.
html
do
redirect_to
(
project_labels_path
(
@project
),
status:
303
)
redirect_to
(
project_labels_path
(
@project
,
body_data:
get_body_data_page
(
project_labels_path
(
@project
))
),
status:
303
)
end
format
.
js
end
...
...
app/controllers/projects/milestones_controller.rb
View file @
f42397d1
class
Projects::MilestonesController
<
Projects
::
ApplicationController
include
MilestoneActions
include
FlashHelper
before_action
:check_issuables_available!
before_action
:milestone
,
only:
[
:edit
,
:update
,
:destroy
,
:show
,
:merge_requests
,
:participants
,
:labels
,
:promote
]
...
...
@@ -70,8 +71,8 @@ class Projects::MilestonesController < Projects::ApplicationController
end
def
promote
promoted_milestone
=
Milestones
::
PromoteService
.
new
(
project
,
current_user
).
execute
(
milestone
)
redirect_to
group_milestone_path
(
project
.
group
,
promoted_milestone
.
iid
),
status:
303
Milestones
::
PromoteService
.
new
(
project
,
current_user
).
execute
(
milestone
)
redirect_to
project_milestones_path
(
project
,
body_data:
get_body_data_page
(
project_milestones_path
(
project
))
),
status:
303
rescue
Milestones
::
PromoteService
::
PromoteMilestoneError
=>
error
redirect_to
milestone
,
alert:
error
.
message
end
...
...
app/helpers/flash_helper.rb
0 → 100644
View file @
f42397d1
module
FlashHelper
def
get_body_data_page
(
path
)
return
unless
path
.
empty?
==
false
path_controller
=
Rails
.
application
.
routes
.
recognize_path
(
path
)
[
path_controller
[
:controller
].
split
(
'/'
),
path_controller
[
:action
]].
compact
.
join
(
':'
)
end
end
spec/controllers/projects/labels_controller_spec.rb
View file @
f42397d1
...
...
@@ -133,7 +133,7 @@ describe Projects::LabelsController do
it
'gives access'
do
post
:promote
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
id:
label_1
.
to_param
expect
(
response
).
to
redirect_to
(
namespace_project_labels_path
)
expect
(
response
.
location
).
to
include
(
namespace_project_labels_path
)
end
it
'promotes the label'
do
...
...
spec/controllers/projects/milestones_controller_spec.rb
View file @
f42397d1
...
...
@@ -98,9 +98,7 @@ describe Projects::MilestonesController do
it
'shows group milestone'
do
post
:promote
,
namespace_id:
project
.
namespace
.
id
,
project_id:
project
.
id
,
id:
milestone
.
iid
group_milestone
=
assigns
(
:milestone
)
expect
(
response
).
to
redirect_to
(
group_milestone_path
(
project
.
group
,
group_milestone
.
iid
))
expect
(
response
.
location
).
to
include
(
project_milestones_path
(
project
))
end
end
...
...
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