Showing
3 changed files
with
79 additions
and
53 deletions
| ... | @@ -16,7 +16,7 @@ router.get('/', function (req, res) { | ... | @@ -16,7 +16,7 @@ router.get('/', function (req, res) { |
| 16 | } | 16 | } |
| 17 | if (videos.length != 0) { | 17 | if (videos.length != 0) { |
| 18 | // 빈 배열 체크 | 18 | // 빈 배열 체크 |
| 19 | - console.log(videos); | 19 | + //console.log(videos); |
| 20 | var items = { | 20 | var items = { |
| 21 | category: category[i], | 21 | category: category[i], |
| 22 | videos: videos, | 22 | videos: videos, | ... | ... |
| ... | @@ -54,53 +54,73 @@ router.get('/products/detail/:id', function (req, res) { | ... | @@ -54,53 +54,73 @@ router.get('/products/detail/:id', function (req, res) { |
| 54 | var video = []; | 54 | var video = []; |
| 55 | //제품정보를 받고 그안에서 댓글을 받아온다. | 55 | //제품정보를 받고 그안에서 댓글을 받아온다. |
| 56 | CategoriModel.find({ product_id: req.params.id }, function (err, comments) { | 56 | CategoriModel.find({ product_id: req.params.id }, function (err, comments) { |
| 57 | - if (word != null) { | 57 | + VideoModel.find(function (err, myVideo) { |
| 58 | - var count = 0; | 58 | + var mitem = []; // 카테고리별 비디오 목록을 담아두는 배열 |
| 59 | - youtube.addParam('order', 'rating'); // 평점 순으로 정렬 | 59 | + var videos = []; // 비디오 목록을 담는 임시 배열 |
| 60 | - youtube.addParam('type', 'video'); // 타입 지정 | 60 | + for (var j in myVideo) { |
| 61 | - youtube.addParam('videoLicense', 'creativeCommon'); // 크리에이티브 커먼즈 아이템만 불러옴 | 61 | + if (product.title == myVideo[j].categori) { |
| 62 | - youtube.search(word, limit, function (err, result) { | 62 | + videos.push(myVideo[j].title); |
| 63 | - // 검색 실행 | 63 | + } |
| 64 | - console.log(word); | 64 | + } |
| 65 | - if (err) { | 65 | + if (videos.length != 0) { |
| 66 | - console.log(err); | 66 | + // 빈 배열 체크 |
| 67 | - } // 에러일 경우 에러공지하고 빠져나감 | 67 | + //console.log(videos); |
| 68 | - //console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력 | 68 | + var items = videos; |
| 69 | - var items = result['items']; // 결과 중 items 항목만 가져옴 | 69 | + mitem.push(items); |
| 70 | - for (var i in items) { | 70 | + } |
| 71 | - var it = items[i]; | 71 | + //console.log(item[2].category.title); |
| 72 | - for (var j in it) { | 72 | + //console.log(item[2].videos); |
| 73 | - if (it[j]['title'] != null) { | 73 | + if (word != null) { |
| 74 | - var title = it[j]['title']; | 74 | + var count = 0; |
| 75 | - } | 75 | + youtube.addParam('order', 'rating'); // 평점 순으로 정렬 |
| 76 | - if (it[j]['videoId'] != null) { | 76 | + youtube.addParam('type', 'video'); // 타입 지정 |
| 77 | - var video_id = it[j]['videoId']; | 77 | + youtube.addParam('videoLicense', 'creativeCommon'); // 크리에이티브 커먼즈 아이템만 불러옴 |
| 78 | + youtube.search(word, limit, function (err, result) { | ||
| 79 | + // 검색 실행 | ||
| 80 | + //console.log(word); | ||
| 81 | + if (err) { | ||
| 82 | + console.log(err); | ||
| 83 | + } // 에러일 경우 에러공지하고 빠져나감 | ||
| 84 | + //console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력 | ||
| 85 | + var items = result['items']; // 결과 중 items 항목만 가져옴 | ||
| 86 | + for (var i in items) { | ||
| 87 | + var it = items[i]; | ||
| 88 | + for (var j in it) { | ||
| 89 | + if (it[j]['title'] != null) { | ||
| 90 | + var title = it[j]['title']; | ||
| 91 | + } | ||
| 92 | + if (it[j]['videoId'] != null) { | ||
| 93 | + var video_id = it[j]['videoId']; | ||
| 94 | + } | ||
| 95 | + var urls = 'https://www.youtube.com/watch?v=' + video_id; | ||
| 78 | } | 96 | } |
| 79 | - var urls = 'https://www.youtube.com/watch?v=' + video_id; | 97 | + var item = { |
| 98 | + id: count, | ||
| 99 | + title: title, | ||
| 100 | + video_id: video_id, | ||
| 101 | + urls: urls, | ||
| 102 | + categori: product.title, | ||
| 103 | + }; | ||
| 104 | + count++; | ||
| 105 | + video.push(item); | ||
| 80 | } | 106 | } |
| 81 | - var item = { | 107 | + res.render('category/productsDetail', { |
| 82 | - id: count, | 108 | + product: product, |
| 83 | - title: title, | 109 | + comments: comments, |
| 84 | - video_id: video_id, | 110 | + videos: video, |
| 85 | - urls: urls, | 111 | + items: mitem, |
| 86 | - categori: product.title, | 112 | + }); |
| 87 | - }; | 113 | + }); |
| 88 | - count++; | 114 | + } else { |
| 89 | - video.push(item); | 115 | + //console.log(item[0]); |
| 90 | - } | ||
| 91 | res.render('category/productsDetail', { | 116 | res.render('category/productsDetail', { |
| 92 | product: product, | 117 | product: product, |
| 93 | comments: comments, | 118 | comments: comments, |
| 94 | videos: video, | 119 | videos: video, |
| 120 | + items: mitem, | ||
| 95 | }); | 121 | }); |
| 96 | - }); | 122 | + } |
| 97 | - } else { | 123 | + }); |
| 98 | - res.render('category/productsDetail', { | ||
| 99 | - product: product, | ||
| 100 | - comments: comments, | ||
| 101 | - videos: video, | ||
| 102 | - }); | ||
| 103 | - } | ||
| 104 | }); | 124 | }); |
| 105 | }); | 125 | }); |
| 106 | }); | 126 | }); | ... | ... |
| ... | @@ -3,6 +3,24 @@ | ... | @@ -3,6 +3,24 @@ |
| 3 | <div class="panel-heading"> | 3 | <div class="panel-heading"> |
| 4 | <%=product.title%> | 4 | <%=product.title%> |
| 5 | </div> | 5 | </div> |
| 6 | + <div style="padding-bottom: 10px"> | ||
| 7 | + 작성일 : | ||
| 8 | + <%=product.getDate.year%> - | ||
| 9 | + <%=product.getDate.month%> - | ||
| 10 | + <%=product.getDate.day%> | ||
| 11 | + </div> | ||
| 12 | + <div> | ||
| 13 | + <% var count=0; %> | ||
| 14 | + 보유중인 영상 | ||
| 15 | + <% for (var i in items[0]) { %> | ||
| 16 | + <div> | ||
| 17 | + <%=items[0][i]%> | ||
| 18 | + </div> | ||
| 19 | + <%count++;};%> | ||
| 20 | + </div> | ||
| 21 | + <div> | ||
| 22 | + 설명 : <%=product.description%> | ||
| 23 | + </div> | ||
| 6 | <form method="get" action=""> | 24 | <form method="get" action=""> |
| 7 | <div class="input-group"> | 25 | <div class="input-group"> |
| 8 | <input type="text" class="form-control" placeholder="검색 키워드를 입력하세요!" name="keyword" autocomplete='off'> | 26 | <input type="text" class="form-control" placeholder="검색 키워드를 입력하세요!" name="keyword" autocomplete='off'> |
| ... | @@ -30,18 +48,6 @@ | ... | @@ -30,18 +48,6 @@ |
| 30 | <button class="btn btn-primary" style="margin-top: 10px; margin-left: 15px;" >영상담기</button> | 48 | <button class="btn btn-primary" style="margin-top: 10px; margin-left: 15px;" >영상담기</button> |
| 31 | </form> | 49 | </form> |
| 32 | <div class="panel-body"> | 50 | <div class="panel-body"> |
| 33 | - <div style="padding-bottom: 10px"> | ||
| 34 | - 작성일 : | ||
| 35 | - <%=product.getDate.year%> - | ||
| 36 | - <%=product.getDate.month%> - | ||
| 37 | - <%=product.getDate.day%> | ||
| 38 | - </div> | ||
| 39 | - <% if(product.thumbnail){%> | ||
| 40 | - <p> | ||
| 41 | - <img src="/uploads/<%=product.thumbnail%>" style="max-width: 100%"/> | ||
| 42 | - </p> | ||
| 43 | - <% } %> | ||
| 44 | - <%=product.description%> | ||
| 45 | <!-- 댓글영역 --> | 51 | <!-- 댓글영역 --> |
| 46 | <div> | 52 | <div> |
| 47 | 댓글작성하기 | 53 | 댓글작성하기 | ... | ... |
-
Please register or login to post a comment