Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // AWS stuff
  2. var bucketName = "<bucket_name>";
  3. var bucketRegion = "us-east-2";
  4. var IdentityPoolId = "<bucket_id>";
  5.  
  6. AWS.config.update({
  7.   region: bucketRegion,
  8.   credentials: new AWS.CognitoIdentityCredentials({
  9.     IdentityPoolId: IdentityPoolId
  10.   })
  11. });
  12.  
  13. var s3 = new AWS.S3({
  14.   apiVersion: "2006-03-01",
  15.   params: { Bucket: bucketName }
  16. });
  17.  
  18. // NOTHING ABOVE THIS LINE IS WORKING AND I HAVE NO IDEA WHY
  19.  
  20. // Let the grid know which columns and what data to use
  21. var gridOptions = {
  22.   animateRows: true,
  23.   rowSelection: 'multiple',
  24.   // event that triggers onCellValueChanged() when a cell is edited
  25.   onCellValueChanged: onCellValueChanged,
  26.  
  27.   defaultColDef: {
  28.     // make all columns editable & resizable
  29.     editable: true,
  30.     resizable: true
  31.   }
  32. };
  33.  
  34. // lookup the container we want the Grid to use
  35. var eGridDiv = document.querySelector('#dataView');
  36.  
  37. // Create the grid passing in the div to use together with the columns & data we want to use
  38. new agGrid.Grid(eGridDiv, gridOptions);
  39.  
  40. // Fetch row data from a JSON file
  41. agGrid.simpleHttpRequest({url: 'https://api.myjson.com/bins/#####'}).then(function(data) {
  42.   gridOptions.api.setRowData(data);
  43. });
  44.  
  45. // Fetch column definitions from a JSON file
  46. agGrid.simpleHttpRequest({url: 'https://api.myjson.com/bins/#####'}).then(function(data) {
  47.   gridOptions.api.setColumnDefs(data);
  48. });
  49.  
  50. // Get selected nodes and do something with them (alert user)
  51. function getSelectedRows() {
  52.   var selectedNodes = gridOptions.api.getSelectedNodes()
  53.   var selectedData = selectedNodes.map( function(node) { return node.data })
  54.   var selectedDataStringPresentation = selectedData.map( function(node) { return node.IDnum + ' ' + node.name }).join(', ')
  55.   alert('Selected nodes: ' + selectedDataStringPresentation);
  56. }
  57.  
  58. function hideLocation() {
  59.   gridOptions.columnApi.setColumnVisible('location', false) // hides location column
  60. }
  61.  
  62. function showLocation() {
  63.   gridOptions.columnApi.setColumnVisible('location', true) // shows location column
  64. }
  65.  
  66. function onCellValueChanged() {
  67.   alert('Edited!');
  68.   // Here is where functionality would go to save
  69.   // the rows to the database in AWS
  70.   console.log("Cell edited");
  71.   // How to get a row's data using the gridOptions api and the rowNode
  72.   //var rowNode = gridOptions.api.getRowNode('1');
  73.   //console.log(rowNode.data);
  74.  
  75.   rowNode = JSON.stringify(gridOptions.api.getRowNode('1'));
  76.   localStorage.setItem('RowData', rowNode);
  77. }
  78.  
  79. function exportCSV(){
  80.   var exporto = gridOptions.api.getDataAsCsv();
  81.   console.log(exporto);
  82. }
  83.  
  84. // NOTHING BELOW THIS LINE IS WORKING AND I DONT KNOW WHY
  85.  
  86. function upload(albumName) {
  87.   var files = "duck";//document.getElementById("photoupload").files;
  88.   if (!files.length) {
  89.     return alert("Please choose a file to upload first.");
  90.   }
  91.   var file = files[0];
  92.   var fileName = file.name;
  93.   var albumPhotosKey = encodeURIComponent(albumName) + "//";
  94.  
  95.   var photoKey = albumPhotosKey + fileName;
  96.  
  97.   // Use S3 ManagedUpload class as it supports multipart uploads
  98.   var upload = new AWS.S3.ManagedUpload({
  99.     params: {
  100.       Bucket: bucketName,
  101.       Key: photoKey,
  102.       Body: file,
  103.       ACL: "public-read"
  104.     }
  105.   });
  106.  
  107.   var promise = upload.promise();
  108.  
  109.   promise.then(
  110.     function(data) {
  111.       alert("Successfully uploaded photo.");
  112.       viewAlbum(albumName);
  113.     },
  114.     function(err) {
  115.       return alert("There was an error uploading your photo: ", err.message);
  116.     }
  117.   );
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement