· 6 years ago · Oct 17, 2019, 01:12 AM
1// AWS stuff
2var bucketName = "<bucket_name>";
3var bucketRegion = "us-east-2";
4var IdentityPoolId = "<bucket_id>";
5
6AWS.config.update({
7 region: bucketRegion,
8 credentials: new AWS.CognitoIdentityCredentials({
9 IdentityPoolId: IdentityPoolId
10 })
11});
12
13var 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
21var 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
35var eGridDiv = document.querySelector('#dataView');
36
37// Create the grid passing in the div to use together with the columns & data we want to use
38new agGrid.Grid(eGridDiv, gridOptions);
39
40// Fetch row data from a JSON file
41agGrid.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
46agGrid.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)
51function 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
58function hideLocation() {
59 gridOptions.columnApi.setColumnVisible('location', false) // hides location column
60}
61
62function showLocation() {
63 gridOptions.columnApi.setColumnVisible('location', true) // shows location column
64}
65
66function 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
79function 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
86function 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}