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
Léo-Paul Géneau
gitlab-ce
Commits
f2f24f05
Commit
f2f24f05
authored
Oct 31, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed up upload feature after master merge
parent
e6a1a798
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
46 deletions
+64
-46
app/assets/javascripts/repo/components/new_dropdown/index.vue
...assets/javascripts/repo/components/new_dropdown/index.vue
+1
-1
app/assets/javascripts/repo/components/new_dropdown/upload.vue
...ssets/javascripts/repo/components/new_dropdown/upload.vue
+8
-7
app/assets/javascripts/repo/components/repo_commit_section.vue
...ssets/javascripts/repo/components/repo_commit_section.vue
+1
-0
app/assets/javascripts/repo/stores/actions.js
app/assets/javascripts/repo/stores/actions.js
+3
-1
app/assets/javascripts/repo/stores/actions/file.js
app/assets/javascripts/repo/stores/actions/file.js
+7
-3
app/assets/javascripts/repo/stores/utils.js
app/assets/javascripts/repo/stores/utils.js
+8
-1
spec/javascripts/repo/components/new_dropdown/upload_spec.js
spec/javascripts/repo/components/new_dropdown/upload_spec.js
+36
-33
No files found.
app/assets/javascripts/repo/components/new_dropdown/index.vue
View file @
f2f24f05
...
@@ -59,7 +59,7 @@
...
@@ -59,7 +59,7 @@
</li>
</li>
<li>
<li>
<upload
<upload
:
current-path=
"currentP
ath"
:
path=
"p
ath"
/>
/>
</li>
</li>
<li>
<li>
...
...
app/assets/javascripts/repo/components/new_dropdown/upload.vue
View file @
f2f24f05
<
script
>
<
script
>
import
eventHub
from
'
../../event_hub
'
;
import
{
mapActions
}
from
'
vuex
'
;
export
default
{
export
default
{
props
:
{
props
:
{
currentP
ath
:
{
p
ath
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
createTempEntry
'
,
]),
createFile
(
target
,
file
,
isText
)
{
createFile
(
target
,
file
,
isText
)
{
const
{
name
}
=
file
;
const
{
name
}
=
file
;
const
nameWithPath
=
`
${
this
.
currentPath
!==
''
?
`
${
this
.
currentPath
}
/`
:
''
}${
name
}
`
;
let
{
result
}
=
target
;
let
{
result
}
=
target
;
if
(
!
isText
)
{
if
(
!
isText
)
{
result
=
result
.
split
(
'
base64,
'
)[
1
];
result
=
result
.
split
(
'
base64,
'
)[
1
];
}
}
eventHub
.
$emit
(
'
createNewEntry
'
,
{
this
.
createTempEntry
(
{
name
:
nameWithPath
,
name
,
type
:
'
blob
'
,
type
:
'
blob
'
,
content
:
result
,
content
:
result
,
toggleModal
:
false
,
base64
:
!
isText
,
base64
:
!
isText
,
}
,
isText
);
});
},
},
readFile
(
file
)
{
readFile
(
file
)
{
const
reader
=
new
FileReader
();
const
reader
=
new
FileReader
();
...
...
app/assets/javascripts/repo/components/repo_commit_section.vue
View file @
f2f24f05
...
@@ -45,6 +45,7 @@ export default {
...
@@ -45,6 +45,7 @@ export default {
action
:
f
.
tempFile
?
'
create
'
:
'
update
'
,
action
:
f
.
tempFile
?
'
create
'
:
'
update
'
,
file_path
:
f
.
path
,
file_path
:
f
.
path
,
content
:
f
.
content
,
content
:
f
.
content
,
encoding
:
f
.
base64
?
'
base64
'
:
'
text
'
,
})),
})),
start_branch
:
createNewBranch
?
this
.
currentBranch
:
undefined
,
start_branch
:
createNewBranch
?
this
.
currentBranch
:
undefined
,
};
};
...
...
app/assets/javascripts/repo/stores/actions.js
View file @
f2f24f05
...
@@ -88,13 +88,15 @@ export const commitChanges = ({ commit, state, dispatch }, { payload, newMr }) =
...
@@ -88,13 +88,15 @@ export const commitChanges = ({ commit, state, dispatch }, { payload, newMr }) =
})
})
.
catch
(()
=>
flash
(
'
Error committing changes. Please try again.
'
));
.
catch
(()
=>
flash
(
'
Error committing changes. Please try again.
'
));
export
const
createTempEntry
=
({
state
,
dispatch
},
{
name
,
type
})
=>
{
export
const
createTempEntry
=
({
state
,
dispatch
},
{
name
,
type
,
content
=
''
,
base64
=
false
})
=>
{
if
(
type
===
'
tree
'
)
{
if
(
type
===
'
tree
'
)
{
dispatch
(
'
createTempTree
'
,
name
);
dispatch
(
'
createTempTree
'
,
name
);
}
else
if
(
type
===
'
blob
'
)
{
}
else
if
(
type
===
'
blob
'
)
{
dispatch
(
'
createTempFile
'
,
{
dispatch
(
'
createTempFile
'
,
{
tree
:
state
,
tree
:
state
,
name
,
name
,
base64
,
content
,
});
});
}
}
};
};
...
...
app/assets/javascripts/repo/stores/actions/file.js
View file @
f2f24f05
...
@@ -80,16 +80,18 @@ export const changeFileContent = ({ commit }, { file, content }) => {
...
@@ -80,16 +80,18 @@ export const changeFileContent = ({ commit }, { file, content }) => {
commit
(
types
.
UPDATE_FILE_CONTENT
,
{
file
,
content
});
commit
(
types
.
UPDATE_FILE_CONTENT
,
{
file
,
content
});
};
};
export
const
createTempFile
=
({
state
,
commit
,
dispatch
},
{
tree
,
name
})
=>
{
export
const
createTempFile
=
({
state
,
commit
,
dispatch
},
{
tree
,
name
,
content
=
''
,
base64
=
''
})
=>
{
const
file
=
createTemp
({
const
file
=
createTemp
({
name
:
name
.
replace
(
`
${
state
.
path
}
/`
,
''
),
name
:
name
.
replace
(
`
${
state
.
path
}
/`
,
''
),
path
:
tree
.
path
,
path
:
tree
.
path
,
type
:
'
blob
'
,
type
:
'
blob
'
,
level
:
tree
.
level
!==
undefined
?
tree
.
level
+
1
:
0
,
level
:
tree
.
level
!==
undefined
?
tree
.
level
+
1
:
0
,
changed
:
true
,
changed
:
true
,
content
,
base64
,
});
});
if
(
findEntry
(
tree
,
'
blob
'
,
file
.
name
))
return
;
if
(
findEntry
(
tree
,
'
blob
'
,
file
.
name
))
return
flash
(
`The name "
${
file
.
name
}
" is already taken in this directory.`
)
;
commit
(
types
.
CREATE_TMP_FILE
,
{
commit
(
types
.
CREATE_TMP_FILE
,
{
parent
:
tree
,
parent
:
tree
,
...
@@ -98,7 +100,9 @@ export const createTempFile = ({ state, commit, dispatch }, { tree, name }) => {
...
@@ -98,7 +100,9 @@ export const createTempFile = ({ state, commit, dispatch }, { tree, name }) => {
commit
(
types
.
TOGGLE_FILE_OPEN
,
file
);
commit
(
types
.
TOGGLE_FILE_OPEN
,
file
);
dispatch
(
'
setFileActive
'
,
file
);
dispatch
(
'
setFileActive
'
,
file
);
if
(
!
state
.
editMode
)
{
if
(
!
state
.
editMode
&&
!
file
.
base64
)
{
dispatch
(
'
toggleEditMode
'
,
true
);
dispatch
(
'
toggleEditMode
'
,
true
);
}
}
return
Promise
.
resolve
(
file
);
};
};
app/assets/javascripts/repo/stores/utils.js
View file @
f2f24f05
...
@@ -24,6 +24,7 @@ export const dataStructure = () => ({
...
@@ -24,6 +24,7 @@ export const dataStructure = () => ({
content
:
''
,
content
:
''
,
parentTreeUrl
:
''
,
parentTreeUrl
:
''
,
renderError
:
false
,
renderError
:
false
,
base64
:
false
,
});
});
export
const
decorateData
=
(
entity
,
projectUrl
=
''
)
=>
{
export
const
decorateData
=
(
entity
,
projectUrl
=
''
)
=>
{
...
@@ -37,12 +38,14 @@ export const decorateData = (entity, projectUrl = '') => {
...
@@ -37,12 +38,14 @@ export const decorateData = (entity, projectUrl = '') => {
tree_url
,
tree_url
,
path
,
path
,
renderError
,
renderError
,
content
=
''
,
tempFile
=
false
,
tempFile
=
false
,
active
=
false
,
active
=
false
,
opened
=
false
,
opened
=
false
,
changed
=
false
,
changed
=
false
,
parentTreeUrl
=
''
,
parentTreeUrl
=
''
,
level
=
0
,
level
=
0
,
base64
=
false
,
}
=
entity
;
}
=
entity
;
return
{
return
{
...
@@ -61,6 +64,8 @@ export const decorateData = (entity, projectUrl = '') => {
...
@@ -61,6 +64,8 @@ export const decorateData = (entity, projectUrl = '') => {
parentTreeUrl
,
parentTreeUrl
,
changed
,
changed
,
renderError
,
renderError
,
content
,
base64
,
// eslint-disable-next-line camelcase
// eslint-disable-next-line camelcase
lastCommit
:
last_commit
?
{
lastCommit
:
last_commit
?
{
url
:
`
${
projectUrl
}
/commit/
${
last_commit
.
id
}
`
,
url
:
`
${
projectUrl
}
/commit/
${
last_commit
.
id
}
`
,
...
@@ -83,7 +88,7 @@ export const pushState = (url) => {
...
@@ -83,7 +88,7 @@ export const pushState = (url) => {
history
.
pushState
({
url
},
''
,
url
);
history
.
pushState
({
url
},
''
,
url
);
};
};
export
const
createTemp
=
({
name
,
path
,
type
,
level
,
changed
,
content
})
=>
{
export
const
createTemp
=
({
name
,
path
,
type
,
level
,
changed
,
content
,
base64
})
=>
{
const
treePath
=
path
?
`
${
path
}
/
${
name
}
`
:
name
;
const
treePath
=
path
?
`
${
path
}
/
${
name
}
`
:
name
;
return
decorateData
({
return
decorateData
({
...
@@ -97,5 +102,7 @@ export const createTemp = ({ name, path, type, level, changed, content }) => {
...
@@ -97,5 +102,7 @@ export const createTemp = ({ name, path, type, level, changed, content }) => {
content
,
content
,
parentTreeUrl
:
''
,
parentTreeUrl
:
''
,
level
,
level
,
base64
,
renderError
:
base64
,
});
});
};
};
spec/javascripts/repo/components/new_dropdown/upload_spec.js
View file @
f2f24f05
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
upload
from
'
~/repo/components/new_dropdown/upload.vue
'
;
import
upload
from
'
~/repo/components/new_dropdown/upload.vue
'
;
import
eventHub
from
'
~/repo/event_hub
'
;
import
store
from
'
~/repo/stores
'
;
import
createComponent
from
'
../../../helpers/vue_mount_component_helper
'
;
import
{
createComponentWithStore
}
from
'
../../../helpers/vue_mount_component_helper
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
describe
(
'
new dropdown upload
'
,
()
=>
{
describe
(
'
new dropdown upload
'
,
()
=>
{
let
vm
;
let
vm
;
...
@@ -9,13 +10,17 @@ describe('new dropdown upload', () => {
...
@@ -9,13 +10,17 @@ describe('new dropdown upload', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
const
Component
=
Vue
.
extend
(
upload
);
const
Component
=
Vue
.
extend
(
upload
);
vm
=
createComponent
(
Component
,
{
vm
=
createComponent
WithStore
(
Component
,
store
,
{
currentP
ath
:
''
,
p
ath
:
''
,
});
});
vm
.
$mount
();
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
vm
.
$destroy
();
vm
.
$destroy
();
resetStore
(
vm
.
$store
);
});
});
describe
(
'
readFile
'
,
()
=>
{
describe
(
'
readFile
'
,
()
=>
{
...
@@ -56,45 +61,43 @@ describe('new dropdown upload', () => {
...
@@ -56,45 +61,43 @@ describe('new dropdown upload', () => {
name
:
'
file
'
,
name
:
'
file
'
,
};
};
beforeEach
(()
=>
{
it
(
'
creates new file
'
,
(
done
)
=>
{
spyOn
(
eventHub
,
'
$emit
'
);
});
it
(
'
emits createNewEntry event
'
,
()
=>
{
vm
.
createFile
(
target
,
file
,
true
);
vm
.
createFile
(
target
,
file
,
true
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
createNewEntry
'
,
{
vm
.
$nextTick
(()
=>
{
name
:
'
file
'
,
expect
(
vm
.
$store
.
state
.
tree
.
length
).
toBe
(
1
);
type
:
'
blob
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
name
).
toBe
(
file
.
name
);
content
:
'
content
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
content
).
toBe
(
target
.
result
);
toggleModal
:
false
,
base64
:
false
,
done
();
}
,
true
);
});
});
});
it
(
'
create
NewEntry event name contains current path
'
,
(
)
=>
{
it
(
'
create
s new file in path
'
,
(
done
)
=>
{
vm
.
currentP
ath
=
'
testing
'
;
vm
.
$store
.
state
.
p
ath
=
'
testing
'
;
vm
.
createFile
(
target
,
file
,
true
);
vm
.
createFile
(
target
,
file
,
true
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
createNewEntry
'
,
{
vm
.
$nextTick
(()
=>
{
name
:
'
testing/file
'
,
expect
(
vm
.
$store
.
state
.
tree
.
length
).
toBe
(
1
);
type
:
'
blob
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
name
).
toBe
(
file
.
name
);
content
:
'
content
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
content
).
toBe
(
target
.
result
);
toggleModal
:
false
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
path
).
toBe
(
`testing/
${
file
.
name
}
`
);
base64
:
false
,
},
true
);
done
();
});
});
});
it
(
'
splits content on base64 if binary
'
,
()
=>
{
it
(
'
splits content on base64 if binary
'
,
(
done
)
=>
{
vm
.
createFile
(
binaryTarget
,
file
,
false
);
vm
.
createFile
(
binaryTarget
,
file
,
false
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
createNewEntry
'
,
{
vm
.
$nextTick
(()
=>
{
name
:
'
file
'
,
expect
(
vm
.
$store
.
state
.
tree
.
length
).
toBe
(
1
);
type
:
'
blob
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
name
).
toBe
(
file
.
name
);
content
:
'
base64content
'
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
content
).
toBe
(
binaryTarget
.
result
.
split
(
'
base64,
'
)[
1
]);
toggleModal
:
false
,
expect
(
vm
.
$store
.
state
.
tree
[
0
].
base64
).
toBe
(
true
);
base64
:
true
,
},
false
);
done
();
});
});
});
});
});
});
});
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