Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.  
  3.   <div>
  4.  
  5.   <!--------------------------------------------------------Navigation------------------------------------------>
  6.   <nav class="navbar navbar-inverse">
  7.     <div class="container-fluid">
  8.       <div class="navbar-header">
  9.         <a class="navbar-brand" href="/">WebSiteName</a>
  10.       </div>
  11.       <ul class="nav navbar-nav">
  12.         <li><router-link :to="{ name: 'projects'}">Projects</router-link></li>
  13.       </ul>
  14.  
  15.       <ul v-if="token == ''" class="nav navbar-nav navbar-right">
  16.         <li><a href="#" data-toggle="modal" data-target="#signupModal"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
  17.         <li><a href="#" data-toggle="modal" data-target="#loginModal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
  18.       </ul>
  19.  
  20.  
  21.       <ul v-if="token != ''" class="nav navbar-nav navbar-right">
  22.         <li><router-link :to="{ name: 'user'}">User</router-link></li>
  23.         <li><a href="#" v-on:click="logout()">Logout</a></li>
  24.       </ul>
  25.     </div>
  26.   </nav>
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.   {{ projects }}
  37.   {{ images }}
  38.  
  39.  
  40. <!-----------------------------------------------LOGIN--------------------------------------------------------------->
  41.  
  42.     <div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria_hidden="true">
  43.       <div class="modal-dialog" role="document">
  44.         <div class="modal-content">
  45.           <div class="modal-header">
  46.             <h5 class="modal-title" id="loginModalLabel">Login</h5>
  47.             <!---<button type="button" class="close" data-dismiss='modal' aria-label="Close">
  48.               <span aria_hidden="true">close</span>
  49.             </button>-->
  50.           </div>
  51.  
  52.           <div class="modal-body">
  53.  
  54.               <form>
  55.                 <input v-model="loginData['input1']" placeholder="Enter ID or Email" />
  56.                 <input v-model="loginData['password']" placeholder="Enter Password" />
  57.                 <br />
  58.                 <br />
  59.                 <button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="login()">
  60.                   Login
  61.                 </button>
  62.                 <button type="button" class="btn btn-default" data-dismiss="modal">
  63.                   Close
  64.                 </button>
  65.               </form>
  66.             </div>
  67.           </div>
  68.         </div>
  69.     </div>
  70.  
  71. <!---------------------------------------------------SIGNUP------------------------------------------------------------>
  72.  
  73.     <div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="signupModalLabel" aria-hidden="true">
  74.       <div class="modal-dialog" role="document">
  75.         <div class="modal-content">
  76.           <div class="modal-header">
  77.             <h5 class="modal-title" id="signupModalLabel">Sign Up</h5>
  78.             <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  79.               <span aria_hidden="true">$times;</span>
  80.             </button>
  81.           </div>
  82.  
  83.           <div class="modal-body">
  84.             <form>
  85.               <input type="text" v-model="signupData['username']" placeholder="User Name" required/><br/>
  86.               <input type="text" v-model="signupData['password']" placeholder="Password" /><br/>
  87.               <input type="text" v-model="signupData['email']" placeholder="Email" /><br/>
  88.               <input type="text" v-model="signupData['location']" placeholder="Location" />
  89.               <br />
  90.               <br />
  91.  
  92.               <button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="signup()">
  93.                 OK
  94.               </button>
  95.  
  96.               <button type="button" class="btn btn-default" data-dismiss="modal">
  97.                 Close
  98.               </button>
  99.             </form>
  100.           </div>
  101.         </div>
  102.       </div>
  103.     </div>
  104.  
  105.     <!--------------------------------Edit project IMAGE--------------------------------------->
  106.     <div class="modal fade" id="editProjectModal" tabindex="-1" role="dialog" aria-labelledby="editProjectModalLabel" aria-hidden="true">
  107.       <div class="modal-dialog" role="document">
  108.         <div class="modal-content">
  109.           <div class="modal-header">
  110.             <h5 class="modal-title" id="editProjectModal">Sign Up</h5>
  111.             <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  112.               <span aria_hidden="true">$times;</span>
  113.             </button>
  114.           </div>
  115.  
  116.           <div class="modal-body">
  117.  
  118.  
  119.             <br/><br/>
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.             <div v-if="!image">
  127.               <h5>Select an image</h5>
  128.               <input type="file" @change="onFileChange">
  129.             </div>
  130.             <div v-else>
  131.               <img :src="image" width="450" height="300" margin="16"/> <br/><br/>
  132.               <button type=button class="btn btn-danger" @click="removeImage">Remove</button>
  133.               <button type=button class="btn btn-success" v-on:click="updateImage()">OK</button>
  134.             </div>
  135.           </div>
  136.  
  137.         </div>
  138.       </div>
  139.     </div>
  140.  
  141. <!------------------------------------REMOVE PROJECT-------------------------------------------->
  142.     <div class="modal fade" id="removeProjectModal" tabindex='-1' role='dialog' aria-labelledby='removeProjectModalLabel' aria_hidden="true">
  143.       <div class="modal-dialog" role="document">
  144.         <div class="modal-content">
  145.           <div class="modal-header">
  146.             <h5 class="modal-title" id="removeProjectModal">Close Project</h5>
  147.             <div class="modal-body">
  148.               <h5>Are you sure?</h5>
  149.  
  150.               <button type="button" class="btn btn-danger" v-on:click="closeProject(project['id'])">DELETE</button>
  151.               <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>
  152.             </div>
  153.           </div>
  154.         </div>
  155.       </div>
  156.     </div>
  157.  
  158. <!----------------------------------------PLEDGE-------------------------------------------------->
  159. <!--pledgeData: {
  160.       "id": '',
  161.       "amount": 0,
  162.       "anonymous": true,
  163.       "card": {
  164.         "authToken": "string"
  165.       }
  166.     }-->
  167.  
  168.   <div class="modal fade" id="pledgeModal" tabindex='-1' role='dialog' aria-labelledby='pledgeModalLabel' aria-hidden='true'>
  169.     <div class='modal-dialog' role='document'>
  170.       <div class='modal-content'>
  171.         <div class='modal-header'>
  172.           <h5 class='modal-title' id='pledgeModal'>Pledge</h5>
  173.           <div class='modal-body'>
  174.           <form>
  175.  
  176.             <input type="number" v-model.number="pledgeData['amount']" placeholder="Enter amount ($)" required/><br/>
  177.             <!--
  178.             <input type="radio" id="anonymous" value=true v-model="pledgeData['anonymous']">
  179.             <input type="radio" id="non-anonymous" value=false v-model="pledgeData['anonymous']">
  180.             -->
  181.  
  182.             <input type="checkbox" id="checkbox" v-model="pledgeData['anonymous']">
  183.             <label for="pledgeData['anonymous']">{{ pledgeData['anonymous'] }}</label>
  184.             <br />
  185.             <br />
  186.  
  187.             <!--<router-link :to="{ name: 'project', params: { projectId: project['id'] }}">-->
  188.             <router-link :to="{ name: 'projects'}">
  189.               <button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="pledge()">
  190.               OK
  191.               </button>
  192.             </router-link>
  193.  
  194.             <button type="button" class="btn btn-default" data-dismiss="modal">
  195.               Close
  196.             </button>
  197.  
  198.             {{ pledgeData }}
  199.  
  200.           </form>
  201.           </div>
  202.         </div>
  203.       </div>
  204.     </div>
  205.   </div>
  206.  
  207.  
  208. <!----------------------------ERROR MESSAGE----------------------------------------->
  209.     <div v-if="errorFlag" style="color: red;">
  210.       {{ this.error}}
  211.     </div>
  212.  
  213.  
  214. <!-------------------------------VIEW SINGLE PROJECT--------------------------------->
  215.     <div class="singleProject" v-if="$route.params.projectId">
  216.       <div id="project">
  217.         <router-link :to="{ name: 'projects'}">Back to Projects</router-link>
  218.  
  219.         <br />
  220.         <br />
  221.         {{ this.project }}
  222.           <tr>
  223.             <td>Title</td>
  224.             <td>Subtitle</td>
  225.             <td>Description</td>
  226.             <td>Target</td>
  227.             <td>Progress</td>
  228.           </tr>
  229.           <tr>
  230.             <td>{{ this.project.title }}</td>
  231.             <td>{{ this.project.subtitle }}</td>
  232.             <td>{{ this.project.description }}</td>
  233.             <td>{{ this.project.target }}</td>
  234.             <td>{{ project['progress']['currentPledged'] }}</td>
  235.           </tr>
  236.           </table>
  237.           <br/>
  238.  
  239.           <div v-if="project['open']!=true">
  240.             <button type="button" id="project_btn" class="btn btn-disabled">Pledge</button>
  241.             <button v-if="token!='' && validateUser($cookie.get('userid'), project['creators'], project['creators'].length) && project['open']==false" type=button class="btn">closed</button>
  242.           </div>
  243.  
  244.           <div v-if="project['open']==true">
  245.             <button v-if="token!=''" type="button" data-toggle="modal" data-target="#pledgeModal" id="project_btn" class="btn btn-primary" v-on:clicked="pledgeData['id']=project['creators'][0]['id']">Pledge</button>
  246.             <button v-if="token==''" type="button" id="project_btn" class="btn btn-disabled">Pledge</button>
  247.             <button v-if="token!='' && validateUser($cookie.get('userid'), project['creators'], project['creators'].length)" type="button" data-toggle="modal" data-target="#editProjectModal" class="btn btn-warning">Edit</button>
  248.             <button v-if="token!='' && validateUser($cookie.get('userid'), project['creators'], project['creators'].length)" type=button data-toggle="modal" data-target="#removeProjectModal" class="btn btn-success">opened</button>
  249.           </div>
  250.  
  251.  
  252.           <br/><br/>
  253.           {{ project['creators'] }}<br/>
  254.           {{ projectPageIndex }}
  255.       </div>
  256.     </div>
  257.  
  258.  
  259.  
  260.  
  261.  
  262. <!---------------------------------ADD NEW PROJECT--------------------------------->
  263.     <div v-else-if="$route.params.new">
  264.       <div id="newProject">
  265.         <h3>Add a new project</h3>
  266.         <form id="needs-validation" novalidate>
  267.           <a>Title</a><br/>
  268.           <input v-model="projectData['title']" placeholder="Enter Title" /><br/>
  269.           <a>Subtitle</a><br/>
  270.           <input v-model="projectData['subtitle']" placeholder="Enter Subtitle" /><br/>
  271.           <a>Description</a><br/>
  272.           <textarea v-model="projectData['description']" placeholder="Enter Description" /><br/>
  273.           <a>Target</a><br/>
  274.           <input v-model.number="projectData['target']" placeholder="Enter Target" /><br/>
  275.           <a>Creators</a><br/>
  276.           <input v-model="creator" placeholder="Add creators" />
  277.           <button type="button" class="btn" v-on:click="addProject_addCreator()">add</button><br/>
  278.  
  279.  
  280.           <br />
  281.           <br />
  282.  
  283.  
  284.           <router-link :to="{ name: 'project', params: { projectId: project.id}}">
  285.             <button type="button" class="btn btn-primary" v-on:click="addProject(); addProject_clear()">
  286.             OK
  287.             </button>
  288.           </router-link>
  289.           <router-link :to="{ name: 'projects'}">
  290.             <button type="button" class="btn btn-default" data-dismiss="modal" v-on:click="addProject_clear()">
  291.               Cancel
  292.             </button>
  293.           </router-link>
  294.           {{ projectData }}
  295.  
  296.         </form>
  297.       </div>
  298.     </div>
  299.  
  300.  
  301. <!-----------------------------PROJECT LIST PAGE------------------------------------------->
  302.     <div v-else>
  303.     <!--{{ projects }}<br/>
  304.     {{ projects_to_display }}-->
  305.     <h3>Project page</h3>
  306.  
  307.  
  308.  
  309.     <button v-if="token==''" id="project_btn" class="btn btn disabled">Add a Project</button>
  310.  
  311.     <router-link v-if="token!=''" :to="{ name: 'newProject', params: { new: 'new'}}">
  312.       <button id="project_btn" class="btn btn-primary ">Add a Project</button>
  313.     </router-link>
  314.  
  315.       <button id="project_btn" class="btn btn-primary" v-on:click="test()">test</button>
  316.  
  317.  
  318.       <!--<div id="project">
  319.         <table>
  320.           <tr v-for="project in projects_to_display">
  321.             <td>
  322.             title: {{ project.title }}<br/>
  323.               id: {{ project.id }} <br/><br/>
  324.             </td>
  325.             <td>
  326.               <router-link :to="{ name: 'project', params: { projectId: project.id}}">
  327.                 <button id="project_btn" class="btn btn-primary" v-on:click="getProject(project.id)">View</button>
  328.               </router-link>
  329.             </td>
  330.           </tr>
  331.         </table>
  332.       </div>-->
  333.  
  334.       <!--<ul class="pagination pagination-lg">
  335.         <li v-for="index in projectPageIndex"><a href='#' v-on:click="getProjects_limit(index)">{{ index/2+1 }}</a></li>
  336.       </ul>-->
  337.  
  338.  
  339.       <div id="project">
  340.         <table>
  341.           <tr v-for="project in projects">
  342.             <td>
  343.             {{ project.title }}<br/>
  344.             {{ project.id }} <br/><br/>
  345.             </td>
  346.             <td>
  347.               <router-link :to="{name: 'project', params: { projectId: project.id}}">
  348.                 <button id="project_btn" class="btn btn-primary" v-on:click="getProject(project.id)">Open</button>
  349.               </router-link>
  350.             </td>
  351.           </tr>
  352.         </table>
  353.       </div>
  354.  
  355.     </div>
  356.   </div>
  357.  
  358.  
  359. </template>
  360.  
  361.  
  362.  
  363. <script>
  364. export default {
  365.   data (){
  366.     return {
  367.       error: "",
  368.       errorFlag: false,
  369.       tokenstatus: false,
  370.       user: {
  371.         "id": '',
  372.         "token": ''
  373.       },
  374.       project_indexAndCount: {
  375.         'index': 1,
  376.         'count': 2
  377.       },
  378.       projectData: {
  379.         "title": "",
  380.         "subtitle": "",
  381.         "description": "",
  382.         "target": 0,
  383.         "creators": [
  384.           {
  385.             "id": ""
  386.           }
  387.         ],
  388.         "rewards": [
  389.           {
  390.             "amount": 0,
  391.             "description": "string"
  392.           }
  393.         ],
  394.       },
  395.       projectPageIndex: [],
  396.       projects: [],
  397.       projects_to_display: [],
  398.       project: [],
  399.       images: [],
  400.       image: "",
  401.       file: "",
  402.  
  403.       imagetest: '',
  404.  
  405.       creator: "",
  406.  
  407.       // username:"",
  408.       // password:"",
  409.       token: '',
  410.  
  411.       signupData: {
  412.         "username": "",
  413.         "email": "",
  414.         "password": "",
  415.         "location": ""
  416.       },
  417.       pledgeData: {
  418.         "id": '',
  419.         "amount": 0,
  420.         "anonymous": true,
  421.         "card": {
  422.           "authToken": "string"
  423.         }
  424.       }
  425.  
  426.     }
  427.   },
  428.   mounted: function(){
  429.     if (this.$cookie.get('token')){
  430.       this.token = this.$cookie.get('token');
  431.       this.tokenStatus = false;
  432.     } else if (this.$cookie.get('token')==undefined){
  433.       this.token = '';
  434.     }
  435.  
  436.     this.projectData["creators"][0]["id"] = parseInt(this.$cookie.get('userid'));
  437.     this.getProjects();
  438.     this.getProjects_limit(0);
  439.     // this.displayProject(0);
  440.     for (var i = 0; i<this.projects.length; i++){
  441.       this.getImage(this.projects[i]['id']);
  442.     }
  443.  
  444.  
  445.  
  446.     // this.projects.sort(function(a, b){
  447.     //   var x = a.title.toLowerCase();
  448.     //   var y = b.title.toLowerCase();
  449.     //   if (x < y) {return -1;}
  450.     //   if (x > y) {return 1;}
  451.     //   return 0;
  452.     // });
  453.  
  454.   },
  455.   methods: {
  456.  
  457.     //ADD PROJECT
  458.     addProject:function(){
  459.       this.$http.post('http://localhost:4941/api/v2/projects', this.projectData, {
  460.         headers :{
  461.           'X-Authorization': this.token
  462.         }
  463.       })
  464.       .then(function(response){
  465.         console.log("addProject Successful!!!");
  466.         alert("Project (" + this.projectData['title'] + ") added!!!");
  467.       }, function(error){
  468.         this.error = error;
  469.         this.errorFlag = true;
  470.       })
  471.     },
  472.     addProject_addCreator: function(){
  473.       this.projectData['creators'].push({'id':this.creator});
  474.       this.creator='';
  475.     },
  476.     addProject_clear: function(){
  477.       this.projectData['title'] = '';
  478.       this.projectData['subtitle'] = '';
  479.       this.projectData['description'] = '';
  480.       this.projectData['target'] = 0;
  481.     },
  482.     displayProject: function(index){
  483.       console.log("displayProject called!!");
  484.       this.projects_to_display = this.projects.slice(index, index+2);
  485.       console.log(this.projects_to_display);
  486.  
  487.     },
  488.     closeProject: function(projectId){
  489.       // console.log("closeProject CALLED");
  490.       // console.log(projectId);
  491.       // console.log(this.token);
  492.       var stats = {
  493.         "open": false
  494.       };
  495.       this.$http.put('http://localhost:4941/api/v2/projects/'+projectId, stats, {
  496.         headers :{
  497.           'X-Authorization': this.token
  498.         }
  499.       })
  500.       .then(function(response){
  501.         console.log("closeProject: SUCCESS")
  502.         this.project['open'] = false;
  503.       }, function(error){
  504.         this.error = error;
  505.         this.errorFlag = true;
  506.       })
  507.     },
  508.     getProjects: function(){
  509.       console.log("getProjects called");
  510.       this.$http.get('http://localhost:4941/api/v2/Projects')
  511.       .then(function(response){
  512.         this.projects = response.data;
  513.         // console.log(response.data);
  514.         var projectlength = Math.ceil(this.projects.length);
  515.         console.log("projectLength: " + projectlength);
  516.         for(var i=0; i <= projectlength; i+=2){
  517.           this.projectPageIndex.push(i);
  518.         }
  519.       }, function(error) {
  520.         this.error = error;
  521.         this.errorFlag = true;
  522.       });
  523.     },
  524.     getProjects_limit: function(index){
  525.       this.$http.get('http://localhost:4941/api/v2/Projects?startIndex='+index+'&count=2')
  526.       .then(function(response){
  527.         this.projects_to_display = response.data;
  528.       }, function(error){
  529.         this.error = error;
  530.         this.errorFlag= true;
  531.       })
  532.     },
  533.     getProject: function(id){
  534.       console.log("getProject called!!!!!!!!!!!!!!");
  535.       this.$http.get('http://localhost:4941/api/v2/Projects/' + id)
  536.       .then(function(response){
  537.         this.project = response.data;
  538.       }, function(error){
  539.         this.error = error;
  540.         this.errorFlag = true;
  541.       });
  542.     },
  543.     // addImage: function(id){
  544.     //   this.$http.put('http://localhost:4941/api/v2/Projects/'+id+'/image', this.image, {
  545.     //     headers :{
  546.     //       'X-Authorization': this.token
  547.     //     }
  548.     //   })
  549.     //   .then(function(response){
  550.     //     console.log("image Added");
  551.     //   }, function(error){
  552.     //     this.error = error;
  553.     //     this.errorFlag = true;
  554.     //   })
  555.     // },
  556.     login: function(){
  557.       console.log(this.username);
  558.       console.log(this.password);
  559.       var isEmail = this.validateEmail(this.loginData["input1"]);
  560.       if (isEmail == true){
  561.         this.$http.post("http://localhost:4941/api/v2/users/login?email="+this.loginData["input1"]+"&password="+this.loginData["password"])
  562.         .then(function(response){
  563.           this.loginData["input1"] = "";
  564.           this.loginData["password"] = "";
  565.           this.token = response.data["token"];
  566.  
  567.           this.$cookie.set('token', response.data["token"], 7);
  568.           this.tokenStatus = true;
  569.           this.user = response.data;
  570.           this.projectData["creators"][0]["id"] = this.user["id"];
  571.           this.$cookie.set('userid', this.user["id"]);
  572.           // console.log(this.projectData);
  573.           // console.log(this.tokenStatus);
  574.         }, function(error){
  575.           this.error = error;
  576.           this.errorFlag = true;
  577.           if (this.error['bodyText'] == "Invalid username/email/password supplied"){
  578.             alert("Invalid username/email/password supplied");
  579.           }
  580.         })
  581.       } else if (isEmail == false) {
  582.         this.$http.post("http://localhost:4941/api/v2/users/login?username="+this.loginData["input1"]+"&password="+this.loginData["password"])
  583.         .then(function(response){
  584.           this.loginData["input1"] = "";
  585.           this.loginData["password"] = "";
  586.  
  587.           this.token = response.data["token"];
  588.           this.$cookie.set('token', response.data["token"], 7);
  589.           this.tokenStatus = true;
  590.           this.user = response.data;
  591.           console.log(this.user);
  592.           this.projectData["creators"][0]["id"] = this.user["id"];
  593.           this.$cookie.set('userid', this.user["id"]);
  594.           console.log(this.projectData);
  595.  
  596.         }, function(error){
  597.           this.error = error;
  598.           this.errorFlag = true;
  599.         })
  600.       }
  601.     },
  602.     logout: function(){
  603.       this.$http.post("http://localhost:4941/api/v2/users/logout", "",{
  604.         headers :{
  605.           'X-Authorization': this.token
  606.         }
  607.       })
  608.       .then(function(response){
  609.         console.log("Logout OK");
  610.         this.tokenstatus = false;
  611.         this.token = "";
  612.         this.$cookie.remove('token');
  613.         this.$cookie.remove('user');
  614.         this.tokenStatus = false;
  615.       }, function(error){
  616.         this.error = error;
  617.         this.errorFlag = true;
  618.       });
  619.     },
  620.     signup: function() {
  621.       // console.log("signup DONE");
  622.       this.$http.post("http://localhost:4941/api/v2/users", this.signupData)
  623.       .then(function(response){
  624.         console.log("signup OK");
  625.         this.loginData['input1'] = this.signupData['username'];
  626.         this.loginData['password']=this.signupData['password'];
  627.         this.login();
  628.  
  629.         this.signupData["username"] = "";
  630.         this.signupData["password"] = "";
  631.         this.signupData["email"] = "";
  632.         this.signupData["location"] = "";
  633.  
  634.  
  635.       }, function(error){
  636.         this.error = error["body"];
  637.         this.errorFlag = true;
  638.         this.signupData["username"] = "";
  639.         this.signupData["password"] = "";
  640.         this.signupData["email"] = "";
  641.         this.signupData["location"] = "";
  642.         if (error["body"] == "Already logged in"){
  643.           console.log("Already logged in");
  644.  
  645.         } else if (error["body"] == "Invalid username/email/password supplied"){
  646.           this.error = console.error();;
  647.           console.log("Invalid username/email/password supplied");
  648.         }
  649.       });
  650.  
  651.     },
  652.     pledge: function() {
  653.       this.$http.post("http://localhost:4941/api/v2/projects/" + this.project['id'] + "/pledge", this.pledgeData,{
  654.         headers :{
  655.           'X-Authorization': this.token
  656.         }
  657.       }).
  658.       then(function(response){
  659.         console.log("pledge OK");
  660.       }, function(error){
  661.         this.error = error;
  662.         this.errorFlag = true;
  663.       });
  664.     },
  665.     // getUser: function(id){
  666.     //   this.$http.get("http://localhost:4941/api/v2/users/" + id, "", {
  667.     //     headers: {
  668.     //       'X-Authorization': this.token
  669.     //     }
  670.     //   })
  671.     //   .then(function(response){
  672.     //     this.user = response.data;
  673.     //   }, function(error){
  674.     //     this.error = error;
  675.     //     this.errorFlag = true;
  676.     //   })
  677.     // },
  678.  
  679.     getImage: function(projectid){
  680.       this.$http.get("http://localhost:4941/api/v2/projects/"+ projectid +"/image")
  681.       // this.$http.get("http://localhost:4941/api/v2/projects/12/image")
  682.       .then(function(response){
  683.         this.images.push({"id": projectid, "image":response.data });
  684.         this.imagetest = response.data;
  685.  
  686.       }, function(error){
  687.         this.error = error;
  688.         this.errorFlag = true;
  689.       });
  690.     },
  691.     updateImage: function(){
  692.       this.$http.put("http://localhost:4941/api/v2/projects/"+ this.project['id'] +"/image", this.file, {
  693.         headers :{
  694.           'Content-Type': 'image/png',
  695.           'X-Authorization': this.token
  696.         }
  697.       }).
  698.       then(function(response){
  699.         console.log('S');
  700.       }, function(error){
  701.         this.error = error;
  702.         this.errorFlag = true;
  703.       });
  704.     },
  705.     onFileChange(e) {
  706.       var files = e.target.files || e.dataTransfer.files;
  707.       if (!files.length)
  708.         return;
  709.       this.createImage(files[0]);
  710.  
  711.     },
  712.  
  713.     createImage(file) {
  714.       var image = new Image();
  715.       var reader = new FileReader();
  716.       var vm = this;
  717.  
  718.       reader.onload = (e) => {
  719.         vm.image = e.target.result;
  720.       };
  721.       reader.readAsDataURL(file);
  722.       this.file = file;
  723.  
  724.     },
  725.     removeImage: function (e) {
  726.       this.image = '';
  727.     },
  728.     convertTobinary: function(image){
  729.  
  730.     },
  731.  
  732.     // validateEmail: function(email){
  733.     //   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  734.     //   console.log(email);
  735.     //   console.log(reg.test(email));
  736.     //   if (reg.test(email) == false){return (false);}
  737.     //   return (true);
  738.     // },
  739.  
  740.  
  741.  
  742.  
  743.  
  744.     validateUser: function(userid, users, numberofCreators){
  745.  
  746.  
  747.       for (var i = 0; i < numberofCreators; i++){
  748.         if (users[i]['id'] == userid){
  749.           return true;
  750.         }
  751.       } return false;
  752.     },
  753.  
  754.     test: function(){
  755.       // console.log(this.$cookie.get('token'));
  756.       // this.$cookie.remove('token');
  757.       // console.log(this.$cookie.get('token'));
  758.       // this.$cookie.remove('token');
  759.       // this.projects_to_display = 'asdf';
  760.       // console.log(this.projects_to_display);
  761.       this.getImage(1);
  762.  
  763.     }
  764.  
  765.  
  766.   }
  767.  
  768.  
  769. }
  770. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement