Skip to content

NTUEEPLUS-298. add "other" options in abroad session for video #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/routes/Schemas/abroad_sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Schema = mongoose.Schema
const Sharing_Schema = new Schema(
{
title: { type: String },
category: { type: String },
intro: { type: String },
YTlink: { type: String },
otherLinks: [{ link: { type: String }, desc: { type: String } }],
Expand All @@ -19,8 +20,8 @@ const { buf2url } = require('./query')
Sharing_Schema.virtual('imgSrc').get(buf2url('img'))

Sharing_Schema.methods.getPublic = function () {
const { title, intro, _id, imgSrc, YTlink, otherLinks, updatedAt } = this
return { title, intro, _id, imgSrc, YTlink, otherLinks, updatedAt }
const { title, category, intro, _id, imgSrc, YTlink, otherLinks, updatedAt } = this
return { title, category, intro, _id, imgSrc, YTlink, otherLinks, updatedAt }
}

module.exports = mongoose.model('Sharing', Sharing_Schema)
6 changes: 4 additions & 2 deletions backend/routes/srcs/in/abroadSharing/addAbroadSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { parseFile } = require('../../../Schemas/query')
* @apiDescription 新增留學分享
*
* @apiParam {String} title 採訪標題
* @apiParam {String} category 文章分類
* @apiParam {String} intro 介紹
* @apiParam {URL} YTlink Youtube連結
* @apiParam {URL[]} otherLinks 其他外部連結
Expand All @@ -21,7 +22,7 @@ const { parseFile } = require('../../../Schemas/query')
* @apiError (500) {String} description 資料庫錯誤
*/
const addAbroadSharing = async (req, res) => {
const { title, intro, YTlink, otherLinks, otherLinksDesc } = req.body
const { title, category, intro, YTlink, otherLinks, otherLinksDesc } = req.body
const img = parseFile(req.file)
if (!otherLinks?.length === otherLinksDesc?.length)
throw new ErrorHandler(
Expand All @@ -30,6 +31,7 @@ const addAbroadSharing = async (req, res) => {

const { _id } = await new AbroadSharing({
title,
category,
intro,
YTlink,
otherLinks: otherLinks?.length
Expand All @@ -44,7 +46,7 @@ const addAbroadSharing = async (req, res) => {

const valid = require('../../../middleware/validation')
const rules = [
{ filename: 'optional', field: ['title', 'intro'], type: 'String' },
{ filename: 'optional', field: ['title', 'category', 'intro'], type: 'String' },
{ filename: 'Url', field: ['YTlink', 'otherLinks'], type: 'URL' },
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { dbCatch, ErrorHandler } = require('../../../error')
* @apiSuccess (201) {String} maxPage 最大頁數
* @apiSuccess (201) {Object[]} data 資料
* @apiSuccess (201) {String} -.title 標題
* @apiSuccess (201) {String} -.category 分類
* @apiSuccess (201) {String} -.intro 介紹
* @apiSuccess (201) {URL} -.YTlink youtube連結
* @apiSuccess (201) {Object[]} -.otherLinks 其他連結
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { dbCatch, ErrorHandler } = require('../../../error')
*
* @apiSuccess (201) {String} image 圖片
* @apiSuccess (201) {String} title 標題
* @apiSuccess (201) {String} category 分類
* @apiSuccess (201) {String} intro 介紹
* @apiSuccess (201) {URL} YTlink youtube連結
* @apiSuccess (201) {URL} otherLinks 其他連結
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { dbCatch, ErrorHandler } = require('../../../error')
* @apiDescription 拿留學分享資訊
*
* @apiSuccess (201) {String} title 標題
* @apiSuccess (201) {String} category 分類
* @apiSuccess (201) {String} intro 介紹
* @apiSuccess (201) {URL} YTlink youtube連結
* @apiSuccess (201) {URL} otherLinks 其他連結
Expand Down
6 changes: 4 additions & 2 deletions backend/routes/srcs/in/abroadSharing/updateAbroadSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { dbCatch, ErrorHandler } = require('../../../error')
*
* @apiParam {String} _id _id
* @apiParam {String} title 標題
* @apiParam {String} category 分類
* @apiParam {String} intro 介紹
* @apiParam {URL} YTlink youtube連結
* @apiParam {URL[]} otherLinks 其他連結
Expand All @@ -25,7 +26,7 @@ const { dbCatch, ErrorHandler } = require('../../../error')
* @apiError (500) {String} description 資料庫錯誤
*/
const updateAbroadSharing = async (req, res, next) => {
const { _id, title, intro, YTlink, otherLinks, otherLinksDesc } = req.body
const { _id, title, category, intro, YTlink, otherLinks, otherLinksDesc } = req.body
if (!_id) throw new ErrorHandler(403, 'please provide _id')
const obj = await abroad_sharing.findOne({ _id }).catch(dbCatch)
if (!obj) throw new ErrorHandler(404, '資料不存在')
Expand All @@ -37,6 +38,7 @@ const updateAbroadSharing = async (req, res, next) => {
const img = parseFile(req.file)
const toSet = updateQuery({
title,
category,
intro,
YTlink,
otherLinks: otherLinks?.length
Expand All @@ -51,7 +53,7 @@ const updateAbroadSharing = async (req, res, next) => {
const valid = require('../../../middleware/validation')
const rules = [
{ filename: 'required', field: '_id' },
{ filename: 'optional', field: ['intro', 'title'], type: 'String' },
{ filename: 'optional', field: ['category', 'intro', 'title'], type: 'String' },
{ filename: 'Url', field: ['YTlink', 'otherLinks'], type: 'URL' },
]

Expand Down
159 changes: 88 additions & 71 deletions client/src/views/in/abroadSession/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FormGroup,
FormControlLabel,
Typography,
Button,
} from '@material-ui/core'
import Pagination from '@material-ui/lab/Pagination'
import { makeStyles } from '@material-ui/core'
Expand Down Expand Up @@ -54,6 +55,7 @@ const useStyles = makeStyles((theme) => ({

const formTemplate = {
title: '',
category: '',
intro: '',
YTlink: '',
otherLinks: [],
Expand Down Expand Up @@ -98,69 +100,51 @@ const Search = ({
.catch((e) => alert(`錯誤: ${e.message}`))
}

const [showStudyAbroadSharing, setShowStudyAbroadSharing] = useState(true)

return (
<div className="d-flex flex-column justify-content-center m-auto w-75">
<Box className={classes.titleSearchContainer}>
<Box className={`display-1 ${classes.title}`}>
<strong>Abroad Sharing Sessions</strong>
<Typography variant="subtitle1" className={classes.controlLabelText}>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={ascTime}
onChange={(e) => setAscTime(e.target.checked)}
inputProps={{ 'aria-label': 'Switch Sorting Order' }}
/>
}
label="Ascending"
></FormControlLabel>
</FormGroup>
</Typography>
{canEdit && (
<CButton onClick={handleAddData} style={{ height: 'min-content' }}>
Add New Data
</CButton>
)}
</Box>
<SearchBar rootRoute={rootRoute} keywords={keywords} setKeywords={setKeywords} />
</Box>
{maxPage === 0 && !isPending ? (
<div className="display-4 d-flex justify-content-center mt-3 text-white">
No corresponding datas
</div>
) : maxPage ? (
<Box my={4} className={classes.paginationContainer}>
<Pagination
count={maxPage}
defaultPage={1}
page={page}
color="secondary"
onChange={(e, val) => {
window.scrollTo(0, 0)
history.push(`${rootRoute}/${val}/${searchFor || ''}`)
}}
/>
<>
<CButton onClick={() => setShowStudyAbroadSharing(!showStudyAbroadSharing)}>
change category
</CButton>

{/* {showStudyAbroadSharing ? (
<div>showStudyAbroadSharing</div>
) : (
<div>showOthers</div>
)} */}

<div className="d-flex flex-column justify-content-center m-auto w-75">
<Box className={classes.titleSearchContainer}>
<Box className={`display-1 ${classes.title}`}>
<strong>Abroad Sharing Sessions</strong>
<Typography variant="subtitle1" className={classes.controlLabelText}>
<FormGroup>
<FormControlLabel
control={
<Switch
checked={ascTime}
onChange={(e) => setAscTime(e.target.checked)}
inputProps={{ 'aria-label': 'Switch Sorting Order' }}
/>
}
label="Ascending"
></FormControlLabel>
</FormGroup>
</Typography>
{canEdit && (
<CButton onClick={handleAddData} style={{ height: 'min-content' }}>
Add New Data
</CButton>
)}
</Box>
<SearchBar rootRoute={rootRoute} keywords={keywords} setKeywords={setKeywords} />
</Box>
) : (
[]
)}
{isPending === true ? (
<CircularProgress className={classes.progress} color="secondary" />
) : (
<>
{data && (
<div className={classes.blogsContainer}>
<Grid container spacing={1}>
<Articles
data={data}
canEdit={canEdit}
deleteArticle={deleteArticle}
updateArticle={handleUpdateData}
/>
</Grid>
</div>
)}
{maxPage === 0 && !isPending ? (
<div className="display-4 d-flex justify-content-center mt-3 text-white">
No corresponding datas
</div>
) : maxPage ? (
<Box my={4} className={classes.paginationContainer}>
<Pagination
count={maxPage}
Expand All @@ -173,16 +157,49 @@ const Search = ({
}}
/>
</Box>
</>
)}
<FormModal
visible={modalOpen}
setVisible={setModalOpen}
data={forEdit}
setData={setForEdit}
refresh={refresh}
/>
</div>
) : (
[]
)}
{isPending === true ? (
<CircularProgress className={classes.progress} color="secondary" />
) : (
<>
{data && (
<div className={classes.blogsContainer}>
<Grid container spacing={1}>
<Articles
data={data}
canEdit={canEdit}
deleteArticle={deleteArticle}
updateArticle={handleUpdateData}
showStudyAbroadSharing={showStudyAbroadSharing}
/>
</Grid>
</div>
)}
<Box my={4} className={classes.paginationContainer}>
<Pagination
count={maxPage}
defaultPage={1}
page={page}
color="secondary"
onChange={(e, val) => {
window.scrollTo(0, 0)
history.push(`${rootRoute}/${val}/${searchFor || ''}`)
}}
/>
</Box>
</>
)}
<FormModal
visible={modalOpen}
setVisible={setModalOpen}
data={forEdit}
setData={setForEdit}
refresh={refresh}
/>
</div>
</>
)
}
Search.propTypes = {
Expand Down
Loading