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
4e81ad2a
Commit
4e81ad2a
authored
Jul 26, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ci skip] Add constants
parent
cf5cc6a9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
150 additions
and
134 deletions
+150
-134
app/assets/javascripts/notes/components/issue_comment_form.vue
...ssets/javascripts/notes/components/issue_comment_form.vue
+136
-130
app/assets/javascripts/notes/constants.js
app/assets/javascripts/notes/constants.js
+8
-0
app/assets/javascripts/notes/stores/actions.js
app/assets/javascripts/notes/stores/actions.js
+3
-2
app/assets/javascripts/notes/stores/mutations.js
app/assets/javascripts/notes/stores/mutations.js
+3
-2
No files found.
app/assets/javascripts/notes/components/issue_comment_form.vue
View file @
4e81ad2a
<
script
>
<
script
>
/* global Flash */
/* global Flash */
import
userAvatarLink
from
'
../../vue_shared/components/user_avatar/user_avatar_link.vue
'
;
import
userAvatarLink
from
'
../../vue_shared/components/user_avatar/user_avatar_link.vue
'
;
import
markdownField
from
'
../../vue_shared/components/markdown/field.vue
'
;
import
markdownField
from
'
../../vue_shared/components/markdown/field.vue
'
;
import
issueNoteSignedOutWidget
from
'
./issue_note_signed_out_widget.vue
'
;
import
issueNoteSignedOutWidget
from
'
./issue_note_signed_out_widget.vue
'
;
import
eventHub
from
'
../event_hub
'
;
import
eventHub
from
'
../event_hub
'
;
import
*
as
constants
from
'
../constants
'
;
export
default
{
export
default
{
data
()
{
data
()
{
const
{
create_note_path
,
state
}
=
window
.
gl
.
issueData
;
const
{
create_note_path
,
state
}
=
window
.
gl
.
issueData
;
const
{
currentUserData
}
=
window
.
gl
;
const
{
currentUserData
}
=
window
.
gl
;
return
{
return
{
note
:
''
,
note
:
''
,
markdownDocsUrl
:
''
,
markdownDocsUrl
:
''
,
markdownPreviewUrl
:
gl
.
issueData
.
preview_note_path
,
markdownPreviewUrl
:
gl
.
issueData
.
preview_note_path
,
noteType
:
'
comment
'
,
noteType
:
constants
.
COMMENT
,
issueState
:
state
,
issueState
:
state
,
endpoint
:
create_note_path
,
endpoint
:
create_note_path
,
author
:
currentUserData
,
author
:
currentUserData
,
};
};
},
components
:
{
userAvatarLink
,
markdownField
,
issueNoteSignedOutWidget
,
},
computed
:
{
isLoggedIn
()
{
return
window
.
gon
.
current_user_id
;
},
commentButtonTitle
()
{
return
this
.
noteType
===
'
comment
'
?
'
Comment
'
:
'
Start discussion
'
;
},
},
isIssueOpen
()
{
components
:
{
return
this
.
issueState
===
'
opened
'
||
this
.
issueState
===
'
reopened
'
;
userAvatarLink
,
markdownField
,
issueNoteSignedOutWidget
,
},
},
issueActionButtonTitle
()
{
computed
:
{
if
(
this
.
note
.
length
)
{
isLoggedIn
()
{
const
actionText
=
this
.
isIssueOpen
?
'
close
'
:
'
reopen
'
;
return
window
.
gon
.
current_user_id
;
},
commentButtonTitle
()
{
return
this
.
noteType
===
constants
.
COMMENT
?
'
Comment
'
:
'
Start discussion
'
;
},
isIssueOpen
()
{
return
this
.
issueState
===
constants
.
OPENED
||
this
.
issueState
===
constants
.
REOPENED
;
},
issueActionButtonTitle
()
{
if
(
this
.
note
.
length
)
{
const
actionText
=
this
.
isIssueOpen
?
'
close
'
:
'
reopen
'
;
return
this
.
noteType
===
'
comment
'
?
`Comment &
${
actionText
}
issue`
:
`Start discussion &
${
actionText
}
issue`
;
return
this
.
noteType
===
constants
.
COMMENT
?
`Comment &
${
actionText
}
issue`
:
`Start discussion &
${
actionText
}
issue`
;
}
}
return
this
.
isIssueOpen
?
'
Close issue
'
:
'
Reopen issue
'
;
return
this
.
isIssueOpen
?
'
Close issue
'
:
'
Reopen issue
'
;
},
},
actionButtonClassNames
()
{
actionButtonClassNames
()
{
return
{
return
{
'
btn-reopen
'
:
!
this
.
isIssueOpen
,
'
btn-reopen
'
:
!
this
.
isIssueOpen
,
'
btn-close
'
:
this
.
isIssueOpen
,
'
btn-close
'
:
this
.
isIssueOpen
,
'
js-note-target-close
'
:
this
.
isIssueOpen
,
'
js-note-target-close
'
:
this
.
isIssueOpen
,
'
js-note-target-reopen
'
:
!
this
.
isIssueOpen
,
'
js-note-target-reopen
'
:
!
this
.
isIssueOpen
,
};
};
},
},
canUpdateIssue
()
{
canUpdateIssue
()
{
const
{
issueData
}
=
window
.
gl
;
const
{
issueData
}
=
window
.
gl
;
return
issueData
&&
issueData
.
current_user
.
can_update
;
return
issueData
&&
issueData
.
current_user
.
can_update
;
},
},
},
},
methods
:
{
methods
:
{
handleSave
(
withIssueAction
)
{
handleSave
(
withIssueAction
)
{
if
(
this
.
note
.
length
)
{
if
(
this
.
note
.
length
)
{
const
noteData
=
{
const
noteData
=
{
endpoint
:
this
.
endpoint
,
endpoint
:
this
.
endpoint
,
flashContainer
:
this
.
$el
,
flashContainer
:
this
.
$el
,
data
:
{
data
:
{
full_data
:
true
,
full_data
:
true
,
note
:
{
note
:
{
noteable_type
:
'
Issue
'
,
noteable_type
:
'
Issue
'
,
noteable_id
:
window
.
gl
.
issueData
.
id
,
noteable_id
:
window
.
gl
.
issueData
.
id
,
note
:
this
.
note
,
note
:
this
.
note
,
}
,
},
},
},
};
};
if
(
this
.
noteType
===
'
discussion
'
)
{
if
(
this
.
noteType
===
constants
.
DISCUSSION
)
{
noteData
.
data
.
note
.
type
=
'
DiscussionNote
'
;
noteData
.
data
.
note
.
type
=
constants
.
DISCUSSION_NOTE
;
}
}
this
.
$store
.
dispatch
(
'
saveNote
'
,
noteData
)
this
.
$store
.
dispatch
(
'
saveNote
'
,
noteData
)
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
if
(
res
.
errors
)
{
if
(
res
.
errors
)
{
if
(
res
.
errors
.
commands_only
)
{
if
(
res
.
errors
.
commands_only
)
{
this
.
discard
();
this
.
discard
();
}
else
{
this
.
handleError
();
}
}
else
{
}
else
{
this
.
handleError
();
this
.
discard
();
}
}
}
else
{
})
this
.
discard
();
.
catch
(()
=>
{
}
this
.
discard
(
false
);
})
});
.
catch
(()
=>
{
this
.
discard
(
false
);
});
}
if
(
withIssueAction
)
{
if
(
this
.
isIssueOpen
)
{
gl
.
issueData
.
state
=
'
closed
'
;
this
.
issueState
=
'
closed
'
;
}
else
{
gl
.
issueData
.
state
=
'
reopened
'
;
this
.
issueState
=
'
reopened
'
;
}
}
this
.
isIssueOpen
=
!
this
.
isIssueOpen
;
// This is out of scope for the Notes Vue component.
if
(
withIssueAction
)
{
// It was the shortest path to update the issue state and relevant places.
if
(
this
.
isIssueOpen
)
{
const
btnClass
=
this
.
isIssueOpen
?
'
btn-reopen
'
:
'
btn-close
'
;
gl
.
issueData
.
state
=
constants
.
CLOSED
;
$
(
`.js-btn-issue-action.
${
btnClass
}
:visible`
).
trigger
(
'
click
'
);
this
.
issueState
=
constants
.
CLOSED
;
}
}
else
{
},
gl
.
issueData
.
state
=
constants
.
REOPENED
;
discard
(
shouldClear
=
true
)
{
this
.
issueState
=
constants
.
REOPENED
;
// `blur` is needed to clear slash commands autocomplete cache if event fired.
}
// `focus` is needed to remain cursor in the textarea.
this
.
isIssueOpen
=
!
this
.
isIssueOpen
;
this
.
$refs
.
textarea
.
blur
();
this
.
$refs
.
textarea
.
focus
();
if
(
shouldClear
)
{
// This is out of scope for the Notes Vue component.
this
.
note
=
''
;
// It was the shortest path to update the issue state and relevant places.
}
const
btnClass
=
this
.
isIssueOpen
?
'
btn-reopen
'
:
'
btn-close
'
;
},
$
(
`.js-btn-issue-action.
${
btnClass
}
:visible`
).
trigger
(
'
click
'
);
setNoteType
(
type
)
{
}
this
.
noteType
=
type
;
},
},
discard
(
shouldClear
=
true
)
{
handleError
()
{
// `blur` is needed to clear slash commands autocomplete cache if event fired.
Flash
(
'
Something went wrong while adding your comment. Please try again.
'
);
// `focus` is needed to remain cursor in the textarea.
},
this
.
$refs
.
textarea
.
blur
();
editMyLastNote
()
{
this
.
$refs
.
textarea
.
focus
();
if
(
this
.
note
===
''
)
{
const
myLastNoteId
=
$
(
'
.js-my-note
'
).
last
().
attr
(
'
id
'
);
if
(
shouldClear
)
{
this
.
note
=
''
;
}
},
setNoteType
(
type
)
{
this
.
noteType
=
type
;
},
handleError
()
{
Flash
(
'
Something went wrong while adding your comment. Please try again.
'
);
},
editMyLastNote
()
{
if
(
this
.
note
===
''
)
{
const
myLastNoteId
=
$
(
'
.js-my-note
'
).
last
().
attr
(
'
id
'
);
if
(
myLastNoteId
)
{
if
(
myLastNoteId
)
{
eventHub
.
$emit
(
'
enterEditMode
'
,
{
eventHub
.
$emit
(
'
enterEditMode
'
,
{
noteId
:
parseInt
(
myLastNoteId
.
replace
(
'
note_
'
,
''
),
10
),
noteId
:
parseInt
(
myLastNoteId
.
replace
(
'
note_
'
,
''
),
10
),
});
});
}
}
}
}
}
,
},
},
},
mounted
()
{
mounted
()
{
const
issuableDataEl
=
document
.
getElementById
(
'
js-issuable-app-initial-data
'
);
const
issuableDataEl
=
document
.
getElementById
(
'
js-issuable-app-initial-data
'
);
const
issueData
=
JSON
.
parse
(
issuableDataEl
.
innerHTML
.
replace
(
/"/g
,
'
"
'
));
const
issueData
=
JSON
.
parse
(
issuableDataEl
.
innerHTML
.
replace
(
/"/g
,
'
"
'
));
this
.
markdownDocsUrl
=
issueData
.
markdownDocs
;
this
.
markdownDocsUrl
=
issueData
.
markdownDocs
;
eventHub
.
$on
(
'
issueStateChanged
'
,
(
isClosed
)
=>
{
this
.
issueState
=
isClosed
?
constants
.
CLOSED
:
constants
.
REOPENED
;
});
},
eventHub
.
$on
(
'
issueStateChanged
'
,
(
isClosed
)
=>
{
destroyed
()
{
this
.
issueState
=
isClosed
?
'
closed
'
:
'
reopened
'
;
eventHub
.
$off
(
'
issueStateChanged
'
);
});
}
},
};
};
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -167,7 +172,8 @@ export default {
...
@@ -167,7 +172,8 @@ export default {
:link-href=
"author.path"
:link-href=
"author.path"
:img-src=
"author.avatar_url"
:img-src=
"author.avatar_url"
:img-alt=
"author.name"
:img-alt=
"author.name"
:img-size=
"40"
/>
:img-size=
"40"
/>
</div>
</div>
<div
class=
"js-main-target-form timeline-content timeline-content-form common-note-form"
>
<div
class=
"js-main-target-form timeline-content timeline-content-form common-note-form"
>
<markdown-field
<markdown-field
...
...
app/assets/javascripts/notes/constants.js
0 → 100644
View file @
4e81ad2a
export
const
DISCUSSION_NOTE
=
'
DiscussionNote
'
;
export
const
DISCUSSION
=
'
discussion
'
;
export
const
NOTE
=
'
note
'
;
export
const
SYSTEM_NOTE
=
'
systemNote
'
;
export
const
COMMENT
=
'
comment
'
;
export
const
OPENED
=
'
opened
'
;
export
const
REOPENED
=
'
reopened
'
;
export
const
CLOSED
=
'
closed
'
;
\ No newline at end of file
app/assets/javascripts/notes/stores/actions.js
View file @
4e81ad2a
/* global Flash */
/* global Flash */
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
utils
from
'
./issue_notes_utils
'
;
import
*
as
utils
from
'
./utils
'
;
import
*
as
constants
from
'
../constants
'
;
import
service
from
'
../services/issue_notes_service
'
;
import
service
from
'
../services/issue_notes_service
'
;
import
loadAwardsHandler
from
'
../../awards_handler
'
;
import
loadAwardsHandler
from
'
../../awards_handler
'
;
import
sidebarTimeTrackingEventHub
from
'
../../sidebar/event_hub
'
;
import
sidebarTimeTrackingEventHub
from
'
../../sidebar/event_hub
'
;
...
@@ -147,7 +148,7 @@ export const poll = ({ commit, state, getters }) => {
...
@@ -147,7 +148,7 @@ export const poll = ({ commit, state, getters }) => {
res
.
notes
.
forEach
((
note
)
=>
{
res
.
notes
.
forEach
((
note
)
=>
{
if
(
notesById
[
note
.
id
])
{
if
(
notesById
[
note
.
id
])
{
commit
(
types
.
UPDATE_NOTE
,
note
);
commit
(
types
.
UPDATE_NOTE
,
note
);
}
else
if
(
note
.
type
===
'
DiscussionNote
'
)
{
}
else
if
(
note
.
type
===
constants
.
DISCUSSION_NOTE
)
{
const
discussion
=
utils
.
findNoteObjectById
(
state
.
notes
,
note
.
discussion_id
);
const
discussion
=
utils
.
findNoteObjectById
(
state
.
notes
,
note
.
discussion_id
);
if
(
discussion
)
{
if
(
discussion
)
{
...
...
app/assets/javascripts/notes/stores/mutations.js
View file @
4e81ad2a
import
*
as
utils
from
'
./utils
'
;
import
*
as
utils
from
'
./utils
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
constants
from
'
../constants
'
;
export
default
{
export
default
{
[
types
.
ADD_NEW_NOTE
](
state
,
note
)
{
[
types
.
ADD_NEW_NOTE
](
state
,
note
)
{
...
@@ -7,7 +8,7 @@ export default {
...
@@ -7,7 +8,7 @@ export default {
const
noteData
=
{
const
noteData
=
{
expanded
:
true
,
expanded
:
true
,
id
:
discussion_id
,
id
:
discussion_id
,
individual_note
:
!
(
type
===
'
DiscussionNote
'
),
individual_note
:
!
(
type
===
constants
.
DISCUSSION_NOTE
),
notes
:
[
note
],
notes
:
[
note
],
reply_id
:
discussion_id
,
reply_id
:
discussion_id
,
};
};
...
@@ -78,7 +79,7 @@ export default {
...
@@ -78,7 +79,7 @@ export default {
notesArr
.
push
({
notesArr
.
push
({
individual_note
:
true
,
individual_note
:
true
,
isPlaceholderNote
:
true
,
isPlaceholderNote
:
true
,
placeholderType
:
data
.
isSystemNote
?
'
systemNote
'
:
'
note
'
,
placeholderType
:
data
.
isSystemNote
?
constants
.
SYSTEM_NOTE
:
constants
.
NOTE
,
notes
:
[
notes
:
[
{
{
body
:
data
.
noteBody
,
body
:
data
.
noteBody
,
...
...
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