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
1bfbee56
Commit
1bfbee56
authored
Jun 26, 2018
by
Paul Slaughter
Committed by
Phil Hughes
Jun 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show file in tree on WebIDE open
parent
5f904e9c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
8 deletions
+117
-8
app/assets/javascripts/ide/components/repo_file.vue
app/assets/javascripts/ide/components/repo_file.vue
+34
-5
app/assets/javascripts/ide/stores/actions/tree.js
app/assets/javascripts/ide/stores/actions/tree.js
+13
-0
app/assets/javascripts/ide/stores/mutation_types.js
app/assets/javascripts/ide/stores/mutation_types.js
+1
-0
app/assets/javascripts/ide/stores/mutations/tree.js
app/assets/javascripts/ide/stores/mutations/tree.js
+5
-0
changelogs/unreleased/45703-open-web-ide-file-tree.yml
changelogs/unreleased/45703-open-web-ide-file-tree.yml
+5
-0
spec/javascripts/ide/helpers.js
spec/javascripts/ide/helpers.js
+24
-2
spec/javascripts/ide/stores/actions/tree_spec.js
spec/javascripts/ide/stores/actions/tree_spec.js
+35
-1
No files found.
app/assets/javascripts/ide/components/repo_file.vue
View file @
1bfbee56
...
@@ -95,24 +95,53 @@ export default {
...
@@ -95,24 +95,53 @@ export default {
return
this
.
file
.
changed
||
this
.
file
.
tempFile
||
this
.
file
.
staged
;
return
this
.
file
.
changed
||
this
.
file
.
tempFile
||
this
.
file
.
staged
;
},
},
},
},
mounted
()
{
if
(
this
.
hasPathAtCurrentRoute
())
{
this
.
scrollIntoView
(
true
);
}
},
updated
()
{
updated
()
{
if
(
this
.
file
.
type
===
'
blob
'
&&
this
.
file
.
active
)
{
if
(
this
.
file
.
type
===
'
blob
'
&&
this
.
file
.
active
)
{
this
.
$el
.
scrollIntoView
({
this
.
scrollIntoView
();
behavior
:
'
smooth
'
,
block
:
'
nearest
'
,
});
}
}
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
toggleTreeOpen
'
]),
...
mapActions
([
'
toggleTreeOpen
'
]),
clickFile
()
{
clickFile
()
{
// Manual Action if a tree is selected/opened
// Manual Action if a tree is selected/opened
if
(
this
.
isTree
&&
this
.
$router
.
currentRoute
.
path
===
`/project
${
this
.
file
.
url
}
`
)
{
if
(
this
.
isTree
&&
this
.
hasUrlAtCurrentRoute
()
)
{
this
.
toggleTreeOpen
(
this
.
file
.
path
);
this
.
toggleTreeOpen
(
this
.
file
.
path
);
}
}
router
.
push
(
`/project
${
this
.
file
.
url
}
`
);
router
.
push
(
`/project
${
this
.
file
.
url
}
`
);
},
},
scrollIntoView
(
isInit
=
false
)
{
const
block
=
isInit
&&
this
.
isTree
?
'
center
'
:
'
nearest
'
;
this
.
$el
.
scrollIntoView
({
behavior
:
'
smooth
'
,
block
,
});
},
hasPathAtCurrentRoute
()
{
if
(
!
this
.
$router
||
!
this
.
$router
.
currentRoute
)
{
return
false
;
}
// - strip route up to "/-/" and ending "/"
const
routePath
=
this
.
$router
.
currentRoute
.
path
.
replace
(
/^.*
?[/]
-
[/]
/g
,
''
)
.
replace
(
/
[/]
$/g
,
''
);
// - strip ending "/"
const
filePath
=
this
.
file
.
path
.
replace
(
/
[/]
$/g
,
''
);
return
filePath
===
routePath
;
},
hasUrlAtCurrentRoute
()
{
return
this
.
$router
.
currentRoute
.
path
===
`/project
${
this
.
file
.
url
}
`
;
},
},
},
};
};
</
script
>
</
script
>
...
...
app/assets/javascripts/ide/stores/actions/tree.js
View file @
1bfbee56
...
@@ -9,6 +9,17 @@ export const toggleTreeOpen = ({ commit }, path) => {
...
@@ -9,6 +9,17 @@ export const toggleTreeOpen = ({ commit }, path) => {
commit
(
types
.
TOGGLE_TREE_OPEN
,
path
);
commit
(
types
.
TOGGLE_TREE_OPEN
,
path
);
};
};
export
const
showTreeEntry
=
({
commit
,
dispatch
,
state
},
path
)
=>
{
const
entry
=
state
.
entries
[
path
];
const
parentPath
=
entry
?
entry
.
parentPath
:
''
;
if
(
parentPath
)
{
commit
(
types
.
SET_TREE_OPEN
,
parentPath
);
dispatch
(
'
showTreeEntry
'
,
parentPath
);
}
};
export
const
handleTreeEntryAction
=
({
commit
,
dispatch
},
row
)
=>
{
export
const
handleTreeEntryAction
=
({
commit
,
dispatch
},
row
)
=>
{
if
(
row
.
type
===
'
tree
'
)
{
if
(
row
.
type
===
'
tree
'
)
{
dispatch
(
'
toggleTreeOpen
'
,
row
.
path
);
dispatch
(
'
toggleTreeOpen
'
,
row
.
path
);
...
@@ -21,6 +32,8 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => {
...
@@ -21,6 +32,8 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => {
}
else
{
}
else
{
dispatch
(
'
getFileData
'
,
{
path
:
row
.
path
});
dispatch
(
'
getFileData
'
,
{
path
:
row
.
path
});
}
}
dispatch
(
'
showTreeEntry
'
,
row
.
path
);
};
};
export
const
getLastCommitData
=
({
state
,
commit
,
dispatch
},
tree
=
state
)
=>
{
export
const
getLastCommitData
=
({
state
,
commit
,
dispatch
},
tree
=
state
)
=>
{
...
...
app/assets/javascripts/ide/stores/mutation_types.js
View file @
1bfbee56
...
@@ -28,6 +28,7 @@ export const TOGGLE_BRANCH_OPEN = 'TOGGLE_BRANCH_OPEN';
...
@@ -28,6 +28,7 @@ export const TOGGLE_BRANCH_OPEN = 'TOGGLE_BRANCH_OPEN';
// Tree mutation types
// Tree mutation types
export
const
SET_DIRECTORY_DATA
=
'
SET_DIRECTORY_DATA
'
;
export
const
SET_DIRECTORY_DATA
=
'
SET_DIRECTORY_DATA
'
;
export
const
TOGGLE_TREE_OPEN
=
'
TOGGLE_TREE_OPEN
'
;
export
const
TOGGLE_TREE_OPEN
=
'
TOGGLE_TREE_OPEN
'
;
export
const
SET_TREE_OPEN
=
'
SET_TREE_OPEN
'
;
export
const
SET_LAST_COMMIT_URL
=
'
SET_LAST_COMMIT_URL
'
;
export
const
SET_LAST_COMMIT_URL
=
'
SET_LAST_COMMIT_URL
'
;
export
const
CREATE_TREE
=
'
CREATE_TREE
'
;
export
const
CREATE_TREE
=
'
CREATE_TREE
'
;
export
const
REMOVE_ALL_CHANGES_FILES
=
'
REMOVE_ALL_CHANGES_FILES
'
;
export
const
REMOVE_ALL_CHANGES_FILES
=
'
REMOVE_ALL_CHANGES_FILES
'
;
...
...
app/assets/javascripts/ide/stores/mutations/tree.js
View file @
1bfbee56
...
@@ -6,6 +6,11 @@ export default {
...
@@ -6,6 +6,11 @@ export default {
opened
:
!
state
.
entries
[
path
].
opened
,
opened
:
!
state
.
entries
[
path
].
opened
,
});
});
},
},
[
types
.
SET_TREE_OPEN
](
state
,
path
)
{
Object
.
assign
(
state
.
entries
[
path
],
{
opened
:
true
,
});
},
[
types
.
CREATE_TREE
](
state
,
{
treePath
})
{
[
types
.
CREATE_TREE
](
state
,
{
treePath
})
{
Object
.
assign
(
state
,
{
Object
.
assign
(
state
,
{
trees
:
Object
.
assign
({},
state
.
trees
,
{
trees
:
Object
.
assign
({},
state
.
trees
,
{
...
...
changelogs/unreleased/45703-open-web-ide-file-tree.yml
0 → 100644
View file @
1bfbee56
---
title
:
Update WebIDE to show file in tree on load
merge_request
:
19887
author
:
type
:
changed
spec/javascripts/ide/helpers.js
View file @
1bfbee56
import
*
as
pathUtils
from
'
path
'
;
import
{
decorateData
}
from
'
~/ide/stores/utils
'
;
import
{
decorateData
}
from
'
~/ide/stores/utils
'
;
import
state
from
'
~/ide/stores/state
'
;
import
state
from
'
~/ide/stores/state
'
;
import
commitState
from
'
~/ide/stores/modules/commit/state
'
;
import
commitState
from
'
~/ide/stores/modules/commit/state
'
;
...
@@ -14,13 +15,34 @@ export const resetStore = store => {
...
@@ -14,13 +15,34 @@ export const resetStore = store => {
store
.
replaceState
(
newState
);
store
.
replaceState
(
newState
);
};
};
export
const
file
=
(
name
=
'
name
'
,
id
=
name
,
type
=
''
)
=>
export
const
file
=
(
name
=
'
name
'
,
id
=
name
,
type
=
''
,
parent
=
null
)
=>
decorateData
({
decorateData
({
id
,
id
,
type
,
type
,
icon
:
'
icon
'
,
icon
:
'
icon
'
,
url
:
'
url
'
,
url
:
'
url
'
,
name
,
name
,
path
:
name
,
path
:
parent
?
`
${
parent
.
path
}
/
${
name
}
`
:
name
,
parentPath
:
parent
?
parent
.
path
:
''
,
lastCommit
:
{},
lastCommit
:
{},
});
});
export
const
createEntriesFromPaths
=
(
paths
)
=>
paths
.
map
(
path
=>
({
name
:
pathUtils
.
basename
(
path
),
dir
:
pathUtils
.
dirname
(
path
),
ext
:
pathUtils
.
extname
(
path
),
}))
.
reduce
((
entries
,
path
,
idx
)
=>
{
const
name
=
path
.
name
;
const
parent
=
path
.
dir
?
entries
[
path
.
dir
]
:
null
;
const
type
=
path
.
ext
?
'
blob
'
:
'
tree
'
;
const
entry
=
file
(
name
,
(
idx
+
1
).
toString
(),
type
,
parent
);
return
{
[
entry
.
path
]:
entry
,
...
entries
,
};
},
{});
spec/javascripts/ide/stores/actions/tree_spec.js
View file @
1bfbee56
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
testAction
from
'
spec/helpers/vuex_action_helper
'
;
import
{
showTreeEntry
}
from
'
~/ide/stores/actions/tree
'
;
import
*
as
types
from
'
~/ide/stores/mutation_types
'
;
import
store
from
'
~/ide/stores
'
;
import
store
from
'
~/ide/stores
'
;
import
service
from
'
~/ide/services
'
;
import
service
from
'
~/ide/services
'
;
import
router
from
'
~/ide/ide_router
'
;
import
router
from
'
~/ide/ide_router
'
;
import
{
file
,
resetStore
}
from
'
../../helpers
'
;
import
{
file
,
resetStore
,
createEntriesFromPaths
}
from
'
../../helpers
'
;
describe
(
'
Multi-file store tree actions
'
,
()
=>
{
describe
(
'
Multi-file store tree actions
'
,
()
=>
{
let
projectTree
;
let
projectTree
;
...
@@ -96,6 +99,37 @@ describe('Multi-file store tree actions', () => {
...
@@ -96,6 +99,37 @@ describe('Multi-file store tree actions', () => {
});
});
});
});
describe
(
'
showTreeEntry
'
,
()
=>
{
beforeEach
(()
=>
{
const
paths
=
[
'
grandparent
'
,
'
ancestor
'
,
'
grandparent/parent
'
,
'
grandparent/aunt
'
,
'
grandparent/parent/child.txt
'
,
'
grandparent/aunt/cousing.txt
'
,
];
Object
.
assign
(
store
.
state
.
entries
,
createEntriesFromPaths
(
paths
));
});
it
(
'
opens the parents
'
,
done
=>
{
testAction
(
showTreeEntry
,
'
grandparent/parent/child.txt
'
,
store
.
state
,
[
{
type
:
types
.
SET_TREE_OPEN
,
payload
:
'
grandparent/parent
'
},
{
type
:
types
.
SET_TREE_OPEN
,
payload
:
'
grandparent
'
},
],
[
{
type
:
'
showTreeEntry
'
},
],
done
,
);
});
});
describe
(
'
getLastCommitData
'
,
()
=>
{
describe
(
'
getLastCommitData
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
spyOn
(
service
,
'
getTreeLastCommit
'
).
and
.
returnValue
(
spyOn
(
service
,
'
getTreeLastCommit
'
).
and
.
returnValue
(
...
...
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