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
Boxiang Sun
gitlab-ce
Commits
78c4a275
Commit
78c4a275
authored
Jul 20, 2017
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move repo_helper methods to related classes
parent
65e8edae
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
161 additions
and
158 deletions
+161
-158
app/assets/javascripts/repo/repo_editor.js
app/assets/javascripts/repo/repo_editor.js
+2
-2
app/assets/javascripts/repo/repo_file_buttons.js
app/assets/javascripts/repo/repo_file_buttons.js
+1
-3
app/assets/javascripts/repo/repo_helper.js
app/assets/javascripts/repo/repo_helper.js
+30
-147
app/assets/javascripts/repo/repo_service.js
app/assets/javascripts/repo/repo_service.js
+10
-0
app/assets/javascripts/repo/repo_sidebar.js
app/assets/javascripts/repo/repo_sidebar.js
+1
-1
app/assets/javascripts/repo/repo_store.js
app/assets/javascripts/repo/repo_store.js
+114
-0
app/assets/javascripts/repo/repo_tab.js
app/assets/javascripts/repo/repo_tab.js
+3
-5
No files found.
app/assets/javascripts/repo/repo_editor.js
View file @
78c4a275
...
...
@@ -16,7 +16,7 @@ export default class RepoEditor {
}
onMonacoEditorKeysPressed
()
{
Helper
.
setActiveFileContents
(
this
.
monacoEditor
.
getValue
());
Store
.
setActiveFileContents
(
this
.
monacoEditor
.
getValue
());
}
initMonaco
()
{
...
...
@@ -110,7 +110,7 @@ export default class RepoEditor {
monaco
.
editor
.
createModel
(
this
.
blobRaw
,
Helper
.
getLanguageForFile
(
.
getLanguage
ID
ForFile
(
this
.
activeFile
,
monaco
.
languages
.
getLanguages
(),
),
...
...
app/assets/javascripts/repo/repo_file_buttons.js
View file @
78c4a275
...
...
@@ -52,9 +52,7 @@ export default class RepoFileButtons {
},
methods
:
{
rawPreviewToggle
()
{
Helper
.
setCurrentFileRawOrPreview
();
},
rawPreviewToggle
:
Store
.
toggleRawPreview
,
},
});
}
...
...
app/assets/javascripts/repo/repo_helper.js
View file @
78c4a275
...
...
@@ -15,7 +15,7 @@ const RepoHelper = {
?
window
.
performance
:
Date
,
getLanguageForFile
(
file
,
langs
)
{
getLanguage
ID
ForFile
(
file
,
langs
)
{
const
ext
=
file
.
name
.
split
(
'
.
'
).
pop
();
const
foundLang
=
this
.
findLanguage
(
ext
,
langs
);
...
...
@@ -26,105 +26,6 @@ const RepoHelper = {
langs
.
find
(
lang
=>
lang
.
extensions
&&
lang
.
extensions
.
indexOf
(
`.
${
ext
}
`
)
>
-
1
);
},
blobURLtoParent
(
url
)
{
const
urlArray
=
url
.
split
(
'
/
'
);
urlArray
.
pop
();
const
blobIndex
=
urlArray
.
indexOf
(
'
blob
'
);
if
(
blobIndex
>
-
1
)
urlArray
[
blobIndex
]
=
'
tree
'
;
return
urlArray
.
join
(
'
/
'
);
},
insertNewFilesIntoParentDir
(
inDirectory
,
oldList
,
newList
)
{
if
(
!
inDirectory
)
return
newList
;
const
indexOfFile
=
oldList
.
findIndex
(
file
=>
file
.
url
===
inDirectory
.
url
);
if
(
!
indexOfFile
)
return
newList
;
return
this
.
mergeNewListToOldList
(
newList
,
oldList
,
inDirectory
,
indexOfFile
);
},
mergeNewListToOldList
(
newList
,
oldList
,
inDirectory
,
indexOfFile
)
{
newList
.
forEach
((
newFile
)
=>
{
const
file
=
newFile
;
file
.
level
=
inDirectory
.
level
+
1
;
oldList
.
splice
(
indexOfFile
,
0
,
file
);
});
return
oldList
;
},
resetBinaryTypes
()
{
const
binaryTypeKeys
=
Object
.
keys
(
Store
.
binaryTypes
);
binaryTypeKeys
.
forEach
((
typeKey
)
=>
{
Store
.
binaryTypes
[
typeKey
]
=
false
;
});
},
setCurrentFileRawOrPreview
()
{
Store
.
activeFile
.
raw
=
!
Store
.
activeFile
.
raw
;
Store
.
activeFileLabel
=
Store
.
activeFile
.
raw
?
'
Preview
'
:
'
Raw
'
;
},
setActiveFile
(
file
)
{
if
(
this
.
isActiveFile
(
file
))
return
;
Store
.
openedFiles
=
Store
.
openedFiles
.
map
((
openedFile
,
i
)
=>
{
const
activeFile
=
openedFile
;
activeFile
.
active
=
file
.
url
===
activeFile
.
url
;
if
(
activeFile
.
active
)
{
Store
.
activeFile
=
activeFile
;
Store
.
activeFileIndex
=
i
;
}
return
activeFile
;
});
this
.
setActiveToRaw
();
if
(
file
.
binary
)
{
Store
.
blobRaw
=
file
.
base64
;
}
else
{
Store
.
blobRaw
=
file
.
plain
;
}
if
(
!
file
.
loading
)
this
.
toURL
(
file
.
url
);
Store
.
binary
=
file
.
binary
;
},
setActiveToRaw
()
{
Store
.
activeFile
.
raw
=
false
;
// can't get vue to listen to raw for some reason so this for now.
Store
.
activeFileLabel
=
'
Raw
'
;
},
isActiveFile
(
file
)
{
return
file
&&
file
.
url
===
Store
.
activeFile
.
url
;
},
removeFromOpenedFiles
(
file
)
{
if
(
file
.
type
===
'
tree
'
)
return
;
Store
.
openedFiles
=
Store
.
openedFiles
.
filter
(
openedFile
=>
openedFile
.
url
!==
file
.
url
);
},
addToOpenedFiles
(
file
)
{
const
openFile
=
file
;
const
openedFilesAlreadyExists
=
Store
.
openedFiles
.
some
(
openedFile
=>
openedFile
.
url
===
openFile
.
url
);
if
(
openedFilesAlreadyExists
)
return
;
openFile
.
changed
=
false
;
Store
.
openedFiles
.
push
(
openFile
);
},
setDirectoryOpen
(
tree
)
{
if
(
!
tree
)
return
;
...
...
@@ -155,34 +56,9 @@ const RepoHelper = {
.
catch
(
this
.
loadingError
);
},
setActiveFileContents
(
contents
)
{
if
(
!
Store
.
editMode
)
return
;
Store
.
activeFile
.
newContent
=
contents
;
Store
.
activeFile
.
changed
=
Store
.
activeFile
.
plain
!==
Store
.
activeFile
.
newContent
;
Store
.
openedFiles
[
Store
.
activeFileIndex
].
changed
=
Store
.
activeFile
.
changed
;
},
toggleFakeTab
(
loading
,
file
)
{
if
(
loading
)
return
this
.
addPlaceholderFile
();
return
this
.
removeFromOpenedFiles
(
file
);
},
addPlaceholderFile
()
{
const
randomURL
=
this
.
Time
.
now
();
const
newFakeFile
=
{
active
:
false
,
binary
:
true
,
type
:
'
blob
'
,
loading
:
true
,
mime_type
:
'
loading
'
,
name
:
'
loading
'
,
url
:
randomURL
,
};
Store
.
openedFiles
.
push
(
newFakeFile
);
return
newFakeFile
;
if
(
loading
)
return
Store
.
addPlaceholderFile
();
return
Store
.
removeFromOpenedFiles
(
file
);
},
setLoading
(
loading
,
file
)
{
...
...
@@ -196,6 +72,27 @@ const RepoHelper = {
return
undefined
;
},
getNewMergedList
(
inDirectory
,
currentList
,
newList
)
{
if
(
!
inDirectory
)
return
newList
;
const
indexOfFile
=
currentList
.
findIndex
(
file
=>
file
.
url
===
inDirectory
.
url
);
if
(
!
indexOfFile
)
return
newList
;
return
this
.
mergeNewListToOldList
(
newList
,
currentList
,
inDirectory
,
indexOfFile
);
},
mergeNewListToOldList
(
newList
,
oldList
,
inDirectory
,
indexOfFile
)
{
newList
.
forEach
((
newFile
)
=>
{
const
file
=
newFile
;
file
.
level
=
inDirectory
.
level
+
1
;
oldList
.
splice
(
indexOfFile
,
0
,
file
);
});
return
oldList
;
},
getContent
(
treeOrFile
)
{
let
file
=
treeOrFile
;
const
loadingData
=
this
.
setLoading
(
true
);
...
...
@@ -223,12 +120,13 @@ const RepoHelper = {
data
.
url
=
file
.
url
;
data
.
newContent
=
''
;
this
.
addToOpenedFiles
(
data
);
this
.
setActiveFile
(
data
);
Store
.
addToOpenedFiles
(
data
);
Store
.
setActiveFiles
(
data
);
// if the file tree is empty
if
(
Store
.
files
.
length
===
0
)
{
const
parentURL
=
this
.
blobURLtoParent
(
Service
.
url
);
const
parentURL
=
Service
.
blobURLtoParentTree
(
Service
.
url
);
Service
.
url
=
parentURL
;
this
.
getContent
();
}
...
...
@@ -236,8 +134,8 @@ const RepoHelper = {
// it's a tree
this
.
setDirectoryOpen
(
file
);
const
newDirectory
=
this
.
dataToListOfFiles
(
data
);
Store
.
files
=
this
.
insertNewFilesIntoParentDir
(
file
,
Store
.
files
,
newDirectory
);
Store
.
prevURL
=
this
.
blobURLtoParent
(
Service
.
url
);
Store
.
addFilesToDirectory
(
file
,
Store
.
files
,
newDirectory
);
Store
.
prevURL
=
Service
.
blobURLtoParentTree
(
Service
.
url
);
}
})
.
catch
(()
=>
{
...
...
@@ -250,21 +148,6 @@ const RepoHelper = {
return
`fa-
${
icon
}
`
;
},
/* eslint-disable no-param-reassign */
removeChildFilesOfTree
(
tree
)
{
let
foundTree
=
false
;
Store
.
files
=
Store
.
files
.
filter
((
file
)
=>
{
if
(
file
.
url
===
tree
.
url
)
foundTree
=
true
;
if
(
foundTree
)
return
file
.
level
<=
tree
.
level
;
return
true
;
});
tree
.
opened
=
false
;
tree
.
icon
=
'
fa-folder
'
;
},
/* eslint-enable no-param-reassign */
serializeBlob
(
blob
)
{
const
simpleBlob
=
this
.
serializeRepoEntity
(
'
blob
'
,
blob
);
simpleBlob
.
lastCommitMessage
=
blob
.
last_commit
.
message
;
...
...
app/assets/javascripts/repo/repo_service.js
View file @
78c4a275
...
...
@@ -43,6 +43,16 @@ const RepoService = {
bufferToBase64
(
data
)
{
return
new
Buffer
(
data
,
'
binary
'
).
toString
(
'
base64
'
);
},
blobURLtoParentTree
(
url
)
{
const
urlArray
=
url
.
split
(
'
/
'
);
urlArray
.
pop
();
const
blobIndex
=
urlArray
.
indexOf
(
'
blob
'
);
if
(
blobIndex
>
-
1
)
urlArray
[
blobIndex
]
=
'
tree
'
;
return
urlArray
.
join
(
'
/
'
);
},
};
export
default
RepoService
;
app/assets/javascripts/repo/repo_sidebar.js
View file @
78c4a275
...
...
@@ -44,7 +44,7 @@ export default class RepoSidebar {
let
url
=
''
;
if
(
typeof
file
===
'
object
'
)
{
if
(
file
.
type
===
'
tree
'
&&
file
.
opened
)
{
Helper
.
removeChildFilesOfTree
(
file
);
Store
.
removeChildFilesOfTree
(
file
);
}
url
=
file
.
url
;
Service
.
url
=
url
;
...
...
app/assets/javascripts/repo/repo_store.js
View file @
78c4a275
import
RepoHelper
from
'
./repo_helper
'
;
const
RepoStore
=
{
ideEl
:
{},
monacoInstance
:
{},
...
...
@@ -44,5 +46,117 @@ const RepoStore = {
tree
:
false
,
blob
:
false
,
},
// mutations
addFilesToDirectory
(
inDirectory
,
currentList
,
newList
)
{
this
.
files
=
RepoHelper
.
getNewMergedList
(
inDirectory
,
currentList
,
newList
);
},
toggleRawPreview
()
{
this
.
activeFile
.
raw
=
!
this
.
activeFile
.
raw
;
this
.
activeFileLabel
=
this
.
activeFile
.
raw
?
'
Preview
'
:
'
Raw
'
;
},
setActiveFiles
(
file
)
{
if
(
this
.
isActiveFile
(
file
))
return
;
this
.
openedFiles
=
this
.
openedFiles
.
map
((
openedFile
,
i
)
=>
this
.
setFileToActive
(
openedFile
,
i
));
this
.
setActiveToRaw
();
if
(
file
.
binary
)
{
this
.
blobRaw
=
file
.
base64
;
}
else
{
this
.
blobRaw
=
file
.
plain
;
}
if
(
!
file
.
loading
)
RepoHelper
.
toURL
(
file
.
url
);
this
.
binary
=
file
.
binary
;
},
setFileToActive
(
file
,
i
)
{
const
activeFile
=
file
;
activeFile
.
active
=
activeFile
.
url
===
activeFile
.
url
;
if
(
activeFile
.
active
)
this
.
setActiveFile
(
activeFile
,
i
);
return
activeFile
;
},
setActiveFile
(
activeFile
,
i
)
{
this
.
activeFile
=
activeFile
;
this
.
activeFileIndex
=
i
;
},
setActiveToRaw
()
{
this
.
activeFile
.
raw
=
false
;
// can't get vue to listen to raw for some reason so this for now.
this
.
activeFileLabel
=
'
Raw
'
;
},
/* eslint-disable no-param-reassign */
removeChildFilesOfTree
(
tree
)
{
let
foundTree
=
false
;
this
.
files
=
this
.
files
.
filter
((
file
)
=>
{
if
(
file
.
url
===
tree
.
url
)
foundTree
=
true
;
if
(
foundTree
)
return
file
.
level
<=
tree
.
level
;
return
true
;
});
tree
.
opened
=
false
;
tree
.
icon
=
'
fa-folder
'
;
},
/* eslint-enable no-param-reassign */
removeFromOpenedFiles
(
file
)
{
if
(
file
.
type
===
'
tree
'
)
return
;
this
.
openedFiles
=
this
.
openedFiles
.
filter
(
openedFile
=>
openedFile
.
url
!==
file
.
url
);
},
addPlaceholderFile
()
{
const
randomURL
=
RepoHelper
.
Time
.
now
();
const
newFakeFile
=
{
active
:
false
,
binary
:
true
,
type
:
'
blob
'
,
loading
:
true
,
mime_type
:
'
loading
'
,
name
:
'
loading
'
,
url
:
randomURL
,
};
this
.
openedFiles
.
push
(
newFakeFile
);
return
newFakeFile
;
},
addToOpenedFiles
(
file
)
{
const
openFile
=
file
;
const
openedFilesAlreadyExists
=
this
.
openedFiles
.
some
(
openedFile
=>
openedFile
.
url
===
openFile
.
url
);
if
(
openedFilesAlreadyExists
)
return
;
openFile
.
changed
=
false
;
this
.
openedFiles
.
push
(
openFile
);
},
setActiveFileContents
(
contents
)
{
if
(
!
this
.
editMode
)
return
;
this
.
activeFile
.
newContent
=
contents
;
this
.
activeFile
.
changed
=
this
.
activeFile
.
plain
!==
this
.
activeFile
.
newContent
;
this
.
openedFiles
[
this
.
activeFileIndex
].
changed
=
this
.
activeFile
.
changed
;
},
// getters
isActiveFile
(
file
)
{
return
file
&&
file
.
url
===
this
.
activeFile
.
url
;
},
};
export
default
RepoStore
;
app/assets/javascripts/repo/repo_tab.js
View file @
78c4a275
import
Repo
Helper
from
'
./repo_helper
'
;
import
Repo
Store
from
'
./repo_store
'
;
const
RepoTab
=
{
template
:
`
...
...
@@ -27,13 +27,11 @@ const RepoTab = {
},
methods
:
{
tabClicked
(
file
)
{
RepoHelper
.
setActiveFile
(
file
);
},
tabClicked
:
RepoStore
.
setActiveFiles
,
xClicked
(
file
)
{
if
(
file
.
changed
)
return
;
Repo
Helper
.
removeFromOpenedFiles
(
file
);
Repo
Store
.
removeFromOpenedFiles
(
file
);
},
},
};
...
...
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