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
c883b526
Commit
c883b526
authored
Aug 29, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renames file when template type is changed
parent
c0923cbd
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
162 additions
and
36 deletions
+162
-36
app/assets/javascripts/ide/components/file_templates/bar.vue
app/assets/javascripts/ide/components/file_templates/bar.vue
+10
-14
app/assets/javascripts/ide/components/new_dropdown/modal.vue
app/assets/javascripts/ide/components/new_dropdown/modal.vue
+1
-0
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
.../javascripts/ide/stores/modules/file_templates/actions.js
+19
-1
app/assets/javascripts/ide/stores/modules/file_templates/getters.js
.../javascripts/ide/stores/modules/file_templates/getters.js
+5
-2
app/assets/javascripts/ide/stores/mutations.js
app/assets/javascripts/ide/stores/mutations.js
+4
-0
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
...scripts/ide/stores/modules/file_templates/actions_spec.js
+75
-8
spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
...scripts/ide/stores/modules/file_templates/getters_spec.js
+40
-11
spec/javascripts/ide/stores/mutations_spec.js
spec/javascripts/ide/stores/mutations_spec.js
+8
-0
No files found.
app/assets/javascripts/ide/components/file_templates/bar.vue
View file @
c883b526
...
@@ -47,7 +47,7 @@ export default {
...
@@ -47,7 +47,7 @@ export default {
<
template
>
<
template
>
<div
class=
"d-flex align-items-center ide-file-templates"
>
<div
class=
"d-flex align-items-center ide-file-templates"
>
<strong
class=
"
mr-2
"
>
<strong
class=
"
append-right-default
"
>
{{
__
(
'
File templates
'
)
}}
{{
__
(
'
File templates
'
)
}}
</strong>
</strong>
<dropdown
<dropdown
...
@@ -58,7 +58,7 @@ export default {
...
@@ -58,7 +58,7 @@ export default {
/>
/>
<dropdown
<dropdown
v-if=
"showTemplatesDropdown"
v-if=
"showTemplatesDropdown"
:label=
"__('Choose a t
yp
e...')"
:label=
"__('Choose a t
emplat
e...')"
:async=
"true"
:async=
"true"
:searchable=
"true"
:searchable=
"true"
:title=
"__('File templates')"
:title=
"__('File templates')"
...
@@ -66,18 +66,14 @@ export default {
...
@@ -66,18 +66,14 @@ export default {
@
click=
"selecteTemplate"
@
click=
"selecteTemplate"
/>
/>
<transition
name=
"fade"
>
<transition
name=
"fade"
>
<div
v-show=
"updateSuccess"
>
<strong
class=
"text-success mr-2"
>
{{
__
(
'
Template applied
'
)
}}
</strong>
<button
<button
v-show=
"updateSuccess"
type=
"button"
type=
"button"
class=
"btn btn-default"
class=
"btn btn-default"
@
click=
"undoFileTemplate"
@
click=
"undoFileTemplate"
>
>
{{
__
(
'
Undo
'
)
}}
{{
__
(
'
Undo
'
)
}}
</button>
</button>
</div>
</transition>
</transition>
</div>
</div>
</
template
>
</
template
>
...
...
app/assets/javascripts/ide/components/new_dropdown/modal.vue
View file @
c883b526
...
@@ -91,6 +91,7 @@ export default {
...
@@ -91,6 +91,7 @@ export default {
:header-title-text=
"modalTitle"
:header-title-text=
"modalTitle"
:footer-primary-button-text=
"buttonLabel"
:footer-primary-button-text=
"buttonLabel"
footer-primary-button-variant=
"success"
footer-primary-button-variant=
"success"
modal-size=
"lg"
@
submit=
"submitForm"
@
submit=
"submitForm"
@
open=
"focusInput"
@
open=
"focusInput"
@
closed=
"closedModal"
@
closed=
"closedModal"
...
...
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
View file @
c883b526
...
@@ -32,9 +32,23 @@ export const fetchTemplateTypes = ({ dispatch, state }) => {
...
@@ -32,9 +32,23 @@ export const fetchTemplateTypes = ({ dispatch, state }) => {
.
catch
(()
=>
dispatch
(
'
receiveTemplateTypesError
'
));
.
catch
(()
=>
dispatch
(
'
receiveTemplateTypesError
'
));
};
};
export
const
setSelectedTemplateType
=
({
commit
},
type
)
=>
export
const
setSelectedTemplateType
=
({
commit
,
dispatch
,
rootGetters
},
type
)
=>
{
commit
(
types
.
SET_SELECTED_TEMPLATE_TYPE
,
type
);
commit
(
types
.
SET_SELECTED_TEMPLATE_TYPE
,
type
);
if
(
rootGetters
.
activeFile
.
prevPath
===
type
.
name
)
{
dispatch
(
'
discardFileChanges
'
,
rootGetters
.
activeFile
.
path
,
{
root
:
true
});
}
else
if
(
rootGetters
.
activeFile
.
name
!==
type
.
name
)
{
dispatch
(
'
renameEntry
'
,
{
path
:
rootGetters
.
activeFile
.
path
,
name
:
type
.
name
,
},
{
root
:
true
},
);
}
};
export
const
receiveTemplateError
=
({
dispatch
},
template
)
=>
{
export
const
receiveTemplateError
=
({
dispatch
},
template
)
=>
{
dispatch
(
dispatch
(
'
setErrorMessage
'
,
'
setErrorMessage
'
,
...
@@ -80,6 +94,10 @@ export const undoFileTemplate = ({ dispatch, commit, rootGetters }) => {
...
@@ -80,6 +94,10 @@ export const undoFileTemplate = ({ dispatch, commit, rootGetters }) => {
commit
(
types
.
SET_UPDATE_SUCCESS
,
false
);
commit
(
types
.
SET_UPDATE_SUCCESS
,
false
);
eventHub
.
$emit
(
`editor.update.model.new.content.
${
file
.
key
}
`
,
file
.
raw
);
eventHub
.
$emit
(
`editor.update.model.new.content.
${
file
.
key
}
`
,
file
.
raw
);
if
(
file
.
prevPath
)
{
dispatch
(
'
discardFileChanges
'
,
file
.
path
,
{
root
:
true
});
}
};
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
// prevent babel-plugin-rewire from generating an invalid default during karma tests
...
...
app/assets/javascripts/ide/stores/modules/file_templates/getters.js
View file @
c883b526
import
{
activityBarViews
}
from
'
../../../constants
'
;
export
const
templateTypes
=
()
=>
[
export
const
templateTypes
=
()
=>
[
{
{
name
:
'
.gitlab-ci.yml
'
,
name
:
'
.gitlab-ci.yml
'
,
...
@@ -17,7 +19,8 @@ export const templateTypes = () => [
...
@@ -17,7 +19,8 @@ export const templateTypes = () => [
},
},
];
];
export
const
showFileTemplatesBar
=
(
_
,
getters
)
=>
name
=>
export
const
showFileTemplatesBar
=
(
_
,
getters
,
rootState
)
=>
name
=>
getters
.
templateTypes
.
find
(
t
=>
t
.
name
===
name
);
getters
.
templateTypes
.
find
(
t
=>
t
.
name
===
name
)
&&
rootState
.
currentActivityView
===
activityBarViews
.
edit
;
export
default
()
=>
{};
export
default
()
=>
{};
app/assets/javascripts/ide/stores/mutations.js
View file @
c883b526
...
@@ -245,6 +245,10 @@ export default {
...
@@ -245,6 +245,10 @@ export default {
if
(
newEntry
.
type
===
'
blob
'
)
{
if
(
newEntry
.
type
===
'
blob
'
)
{
state
.
changedFiles
=
state
.
changedFiles
.
concat
(
newEntry
);
state
.
changedFiles
=
state
.
changedFiles
.
concat
(
newEntry
);
}
}
if
(
state
.
entries
[
newPath
].
opened
)
{
state
.
openFiles
.
push
(
state
.
entries
[
newPath
]);
}
},
},
...
projectMutations
,
...
projectMutations
,
...
mergeRequestMutation
,
...
mergeRequestMutation
,
...
...
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
View file @
c883b526
...
@@ -148,14 +148,66 @@ describe('IDE file templates actions', () => {
...
@@ -148,14 +148,66 @@ describe('IDE file templates actions', () => {
});
});
describe
(
'
setSelectedTemplateType
'
,
()
=>
{
describe
(
'
setSelectedTemplateType
'
,
()
=>
{
it
(
'
commits SET_SELECTED_TEMPLATE_TYPE
'
,
done
=>
{
it
(
'
commits SET_SELECTED_TEMPLATE_TYPE
'
,
()
=>
{
testAction
(
const
commit
=
jasmine
.
createSpy
(
'
commit
'
);
actions
.
setSelectedTemplateType
,
const
options
=
{
'
test
'
,
commit
,
state
,
dispatch
()
{},
[{
type
:
types
.
SET_SELECTED_TEMPLATE_TYPE
,
payload
:
'
test
'
}],
rootGetters
:
{
[],
activeFile
:
{
done
,
name
:
'
test
'
,
prevPath
:
''
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
commit
).
toHaveBeenCalledWith
(
types
.
SET_SELECTED_TEMPLATE_TYPE
,
{
name
:
'
test
'
});
});
it
(
'
dispatches discardFileChanges if prevPath matches templates name
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
options
=
{
commit
()
{},
dispatch
,
rootGetters
:
{
activeFile
:
{
name
:
'
test
'
,
path
:
'
test
'
,
prevPath
:
'
test
'
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
discardFileChanges
'
,
'
test
'
,
{
root
:
true
});
});
it
(
'
dispatches renameEntry if file name doesnt match
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
options
=
{
commit
()
{},
dispatch
,
rootGetters
:
{
activeFile
:
{
name
:
'
oldtest
'
,
path
:
'
oldtest
'
,
prevPath
:
''
,
},
},
};
actions
.
setSelectedTemplateType
(
options
,
{
name
:
'
test
'
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
renameEntry
'
,
{
path
:
'
oldtest
'
,
name
:
'
test
'
,
},
{
root
:
true
},
);
);
});
});
});
});
...
@@ -332,5 +384,20 @@ describe('IDE file templates actions', () => {
...
@@ -332,5 +384,20 @@ describe('IDE file templates actions', () => {
expect
(
commit
).
toHaveBeenCalledWith
(
'
SET_UPDATE_SUCCESS
'
,
false
);
expect
(
commit
).
toHaveBeenCalledWith
(
'
SET_UPDATE_SUCCESS
'
,
false
);
});
});
it
(
'
dispatches discardFileChanges if file has prevPath
'
,
()
=>
{
const
dispatch
=
jasmine
.
createSpy
(
'
dispatch
'
);
const
rootGetters
=
{
activeFile
:
{
path
:
'
test
'
,
prevPath
:
'
newtest
'
,
raw
:
'
raw content
'
},
};
actions
.
undoFileTemplate
({
dispatch
,
commit
()
{},
rootGetters
});
expect
(
dispatch
.
calls
.
mostRecent
().
args
).
toEqual
([
'
discardFileChanges
'
,
'
test
'
,
{
root
:
true
},
]);
});
});
});
});
});
spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
View file @
c883b526
import
createState
from
'
~/ide/stores/state
'
;
import
{
activityBarViews
}
from
'
~/ide/constants
'
;
import
*
as
getters
from
'
~/ide/stores/modules/file_templates/getters
'
;
import
*
as
getters
from
'
~/ide/stores/modules/file_templates/getters
'
;
describe
(
'
IDE file templates getters
'
,
()
=>
{
describe
(
'
IDE file templates getters
'
,
()
=>
{
...
@@ -8,22 +10,49 @@ describe('IDE file templates getters', () => {
...
@@ -8,22 +10,49 @@ describe('IDE file templates getters', () => {
});
});
describe
(
'
showFileTemplatesBar
'
,
()
=>
{
describe
(
'
showFileTemplatesBar
'
,
()
=>
{
it
(
'
finds template type by name
'
,
()
=>
{
let
rootState
;
beforeEach
(()
=>
{
rootState
=
createState
();
});
it
(
'
returns true if template is found and currentActivityView is edit
'
,
()
=>
{
rootState
.
currentActivityView
=
activityBarViews
.
edit
;
expect
(
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
templateTypes
:
getters
.
templateTypes
(),
})(
'
LICENSE
'
)
,
}
,
).
toEqual
({
rootState
,
name
:
'
LICENSE
'
,
)(
'
LICENSE
'
)
,
key
:
'
licenses
'
,
).
toBe
(
true
);
});
});
it
(
'
returns false if template is found and currentActivityView is not edit
'
,
()
=>
{
rootState
.
currentActivityView
=
activityBarViews
.
commit
;
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
},
rootState
,
)(
'
LICENSE
'
),
).
toBe
(
false
);
});
});
it
(
'
returns undefined if not found
'
,
()
=>
{
it
(
'
returns undefined if not found
'
,
()
=>
{
expect
(
expect
(
getters
.
showFileTemplatesBar
(
null
,
{
getters
.
showFileTemplatesBar
(
null
,
{
templateTypes
:
getters
.
templateTypes
(),
templateTypes
:
getters
.
templateTypes
(),
})(
'
test
'
),
},
rootState
,
)(
'
test
'
),
).
toBe
(
undefined
);
).
toBe
(
undefined
);
});
});
});
});
...
...
spec/javascripts/ide/stores/mutations_spec.js
View file @
c883b526
...
@@ -339,5 +339,13 @@ describe('Multi-file store mutations', () => {
...
@@ -339,5 +339,13 @@ describe('Multi-file store mutations', () => {
expect
(
localState
.
entries
.
parentPath
.
tree
.
length
).
toBe
(
1
);
expect
(
localState
.
entries
.
parentPath
.
tree
.
length
).
toBe
(
1
);
});
});
it
(
'
adds to openFiles if previously opened
'
,
()
=>
{
localState
.
entries
.
oldPath
.
opened
=
true
;
mutations
.
RENAME_ENTRY
(
localState
,
{
path
:
'
oldPath
'
,
name
:
'
newPath
'
});
expect
(
localState
.
openFiles
).
toEqual
([
localState
.
entries
.
newPath
]);
});
});
});
});
});
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