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
892338cb
Commit
892338cb
authored
Mar 13, 2020
by
Nicolò Maria Mezzopera
Committed by
Paul Slaughter
Mar 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor pdf_viewer to sfc
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26894
parent
9b28dc85
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
54 deletions
+130
-54
app/assets/javascripts/blob/pdf/index.js
app/assets/javascripts/blob/pdf/index.js
+7
-47
app/assets/javascripts/blob/pdf/pdf_viewer.vue
app/assets/javascripts/blob/pdf/pdf_viewer.vue
+49
-0
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/frontend/blob/pdf/pdf_viewer_spec.js
spec/frontend/blob/pdf/pdf_viewer_spec.js
+67
-0
spec/frontend/fixtures/static/pdf_viewer.html
spec/frontend/fixtures/static/pdf_viewer.html
+0
-1
spec/javascripts/pdf/index_spec.js
spec/javascripts/pdf/index_spec.js
+0
-3
spec/javascripts/pdf/page_spec.js
spec/javascripts/pdf/page_spec.js
+1
-3
No files found.
app/assets/javascripts/blob/pdf/index.js
View file @
892338cb
import
Vue
from
'
vue
'
;
import
pdfLab
from
'
../../pdf/index.vue
'
;
import
{
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
PdfViewer
from
'
./pdf_viewer.vue
'
;
export
default
()
=>
{
const
el
=
document
.
getElementById
(
'
js-pdf-viewer
'
);
return
new
Vue
({
el
,
components
:
{
pdfLab
,
GlLoadingIcon
,
render
(
createElement
)
{
return
createElement
(
PdfViewer
,
{
props
:
{
pdf
:
el
.
dataset
.
endpoint
,
},
});
},
data
()
{
return
{
error
:
false
,
loadError
:
false
,
loading
:
true
,
pdf
:
el
.
dataset
.
endpoint
,
};
},
methods
:
{
onLoad
()
{
this
.
loading
=
false
;
},
onError
(
error
)
{
this
.
loading
=
false
;
this
.
loadError
=
true
;
this
.
error
=
error
;
},
},
template
:
`
<div class="js-pdf-viewer container-fluid md prepend-top-default append-bottom-default">
<div
class="text-center loading"
v-if="loading && !error">
<gl-loading-icon class="mt-5" size="lg"/>
</div>
<pdf-lab
v-if="!loadError"
:pdf="pdf"
@pdflabload="onLoad"
@pdflaberror="onError" />
<p
class="text-center"
v-if="error">
<span v-if="loadError">
An error occurred while loading the file. Please try again later.
</span>
<span v-else>
An error occurred while decoding the file.
</span>
</p>
</div>
`
,
});
};
app/assets/javascripts/blob/pdf/pdf_viewer.vue
0 → 100644
View file @
892338cb
<
script
>
import
PdfLab
from
'
../../pdf/index.vue
'
;
import
{
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
export
default
{
components
:
{
PdfLab
,
GlLoadingIcon
,
},
props
:
{
pdf
:
{
type
:
String
,
required
:
true
,
},
},
data
()
{
return
{
error
:
false
,
loadError
:
false
,
loading
:
true
,
};
},
methods
:
{
onLoad
()
{
this
.
loading
=
false
;
},
onError
(
error
)
{
this
.
loading
=
false
;
this
.
loadError
=
true
;
this
.
error
=
error
;
},
},
};
</
script
>
<
template
>
<div
class=
"js-pdf-viewer container-fluid md prepend-top-default append-bottom-default"
>
<div
v-if=
"loading && !error"
class=
"text-center loading"
>
<gl-loading-icon
class=
"mt-5"
size=
"lg"
/>
</div>
<pdf-lab
v-if=
"!loadError"
:pdf=
"pdf"
@
pdflabload=
"onLoad"
@
pdflaberror=
"onError"
/>
<p
v-if=
"error"
class=
"text-center"
>
<span
v-if=
"loadError"
ref=
"loadError"
>
{{
__
(
'
An error occurred while loading the file. Please try again later.
'
)
}}
</span>
<span
v-else
>
{{
__
(
'
An error occurred while decoding the file.
'
)
}}
</span>
</p>
</div>
</
template
>
locale/gitlab.pot
View file @
892338cb
...
...
@@ -1786,6 +1786,9 @@ msgstr ""
msgid "An error occurred while committing your changes."
msgstr ""
msgid "An error occurred while decoding the file."
msgstr ""
msgid "An error occurred while deleting the approvers group"
msgstr ""
...
...
@@ -1927,6 +1930,9 @@ msgstr ""
msgid "An error occurred while loading the file."
msgstr ""
msgid "An error occurred while loading the file. Please try again later."
msgstr ""
msgid "An error occurred while loading the merge request changes."
msgstr ""
...
...
spec/
javascripts/blob/pdf/index
_spec.js
→
spec/
frontend/blob/pdf/pdf_viewer
_spec.js
View file @
892338cb
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
{
FIXTURES_PATH
}
from
'
spec/test_constants
'
;
import
renderPDF
from
'
~/blob/pdf
'
;
import
component
from
'
~/blob/pdf/pdf_viewer.vue
'
;
import
PdfLab
from
'
~/pdf/index.vue
'
;
const
testPDF
=
`
${
FIXTURES_PATH
}
/blob/pdf/test.pdf`
;
describe
(
'
PDF renderer
'
,
()
=>
{
let
viewer
;
let
app
;
let
wrapper
;
const
checkLoaded
=
done
=>
{
if
(
app
.
loading
)
{
setTimeout
(()
=>
{
checkLoaded
(
done
);
},
100
);
}
else
{
done
();
}
const
mountComponent
=
()
=>
{
wrapper
=
shallowMount
(
component
,
{
propsData
:
{
pdf
:
testPDF
,
},
});
};
preloadFixtures
(
'
static/pdf_viewer.html
'
);
const
findLoading
=
()
=>
wrapper
.
find
(
GlLoadingIcon
);
const
findPdfLab
=
()
=>
wrapper
.
find
(
PdfLab
);
const
findLoadError
=
()
=>
wrapper
.
find
({
ref
:
'
loadError
'
});
beforeEach
(()
=>
{
loadFixtures
(
'
static/pdf_viewer.html
'
);
viewer
=
document
.
getElementById
(
'
js-pdf-viewer
'
);
viewer
.
dataset
.
endpoint
=
testPDF
;
mountComponent
();
});
it
(
'
shows loading icon
'
,
()
=>
{
renderPDF
();
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
});
expect
(
document
.
querySelector
(
'
.loading
'
)).
not
.
toBeNull
();
it
(
'
shows loading icon
'
,
()
=>
{
expect
(
findLoading
().
exists
()).
toBe
(
true
);
});
describe
(
'
successful response
'
,
()
=>
{
beforeEach
(
done
=>
{
app
=
renderPDF
();
checkLoaded
(
done
);
beforeEach
(()
=>
{
findPdfLab
().
vm
.
$emit
(
'
pdflabload
'
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
)).
toBeNull
(
);
expect
(
findLoading
().
exists
()).
toBe
(
false
);
});
it
(
'
renders the PDF
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.pdf-viewer
'
)).
not
.
toBeNull
();
});
it
(
'
renders the PDF page
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.pdf-page
'
)).
not
.
toBeNull
();
expect
(
findPdfLab
().
exists
()).
toBe
(
true
);
});
});
describe
(
'
error getting file
'
,
()
=>
{
beforeEach
(
done
=>
{
viewer
.
dataset
.
endpoint
=
'
invalid/path/to/file.pdf
'
;
app
=
renderPDF
();
checkLoaded
(
done
);
beforeEach
(()
=>
{
findPdfLab
().
vm
.
$emit
(
'
pdflaberror
'
,
'
foo
'
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
)).
toBeNull
(
);
expect
(
findLoading
().
exists
()).
toBe
(
false
);
});
it
(
'
shows error message
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.md
'
).
textContent
.
trim
()).
toBe
(
expect
(
findLoadError
().
text
()).
toBe
(
'
An error occurred while loading the file. Please try again later.
'
,
);
});
...
...
spec/frontend/fixtures/static/pdf_viewer.html
deleted
100644 → 0
View file @
9b28dc85
<div
class=
"file-content"
data-endpoint=
"/test"
id=
"js-pdf-viewer"
></div>
spec/javascripts/pdf/index_spec.js
View file @
892338cb
import
Vue
from
'
vue
'
;
import
{
GlobalWorkerOptions
}
from
'
pdfjs-dist/build/pdf
'
;
import
workerSrc
from
'
pdfjs-dist/build/pdf.worker.min
'
;
import
{
FIXTURES_PATH
}
from
'
spec/test_constants
'
;
import
PDFLab
from
'
~/pdf/index.vue
'
;
const
pdf
=
`
${
FIXTURES_PATH
}
/blob/pdf/test.pdf`
;
GlobalWorkerOptions
.
workerSrc
=
workerSrc
;
const
Component
=
Vue
.
extend
(
PDFLab
);
describe
(
'
PDF component
'
,
()
=>
{
...
...
spec/javascripts/pdf/page_spec.js
View file @
892338cb
import
Vue
from
'
vue
'
;
import
pdfjsLib
from
'
pdfjs-dist/build/pdf
'
;
import
workerSrc
from
'
pdfjs-dist/build/pdf.worker.min
'
;
import
pdfjsLib
from
'
pdfjs-dist/webpack
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
FIXTURES_PATH
}
from
'
spec/test_constants
'
;
...
...
@@ -14,7 +13,6 @@ describe('Page component', () => {
let
testPage
;
beforeEach
(
done
=>
{
pdfjsLib
.
GlobalWorkerOptions
.
workerSrc
=
workerSrc
;
pdfjsLib
.
getDocument
(
testPDF
)
.
promise
.
then
(
pdf
=>
pdf
.
getPage
(
1
))
...
...
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