Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AWS stuff
- var bucketName = "<bucket_name>";
- var bucketRegion = "us-east-2";
- var IdentityPoolId = "<bucket_id>";
- AWS.config.update({
- region: bucketRegion,
- credentials: new AWS.CognitoIdentityCredentials({
- IdentityPoolId: IdentityPoolId
- })
- });
- var s3 = new AWS.S3({
- apiVersion: "2006-03-01",
- params: { Bucket: bucketName }
- });
- // NOTHING ABOVE THIS LINE IS WORKING AND I HAVE NO IDEA WHY
- // Let the grid know which columns and what data to use
- var gridOptions = {
- animateRows: true,
- rowSelection: 'multiple',
- // event that triggers onCellValueChanged() when a cell is edited
- onCellValueChanged: onCellValueChanged,
- defaultColDef: {
- // make all columns editable & resizable
- editable: true,
- resizable: true
- }
- };
- // lookup the container we want the Grid to use
- var eGridDiv = document.querySelector('#dataView');
- // Create the grid passing in the div to use together with the columns & data we want to use
- new agGrid.Grid(eGridDiv, gridOptions);
- // Fetch row data from a JSON file
- agGrid.simpleHttpRequest({url: 'https://api.myjson.com/bins/#####'}).then(function(data) {
- gridOptions.api.setRowData(data);
- });
- // Fetch column definitions from a JSON file
- agGrid.simpleHttpRequest({url: 'https://api.myjson.com/bins/#####'}).then(function(data) {
- gridOptions.api.setColumnDefs(data);
- });
- // Get selected nodes and do something with them (alert user)
- function getSelectedRows() {
- var selectedNodes = gridOptions.api.getSelectedNodes()
- var selectedData = selectedNodes.map( function(node) { return node.data })
- var selectedDataStringPresentation = selectedData.map( function(node) { return node.IDnum + ' ' + node.name }).join(', ')
- alert('Selected nodes: ' + selectedDataStringPresentation);
- }
- function hideLocation() {
- gridOptions.columnApi.setColumnVisible('location', false) // hides location column
- }
- function showLocation() {
- gridOptions.columnApi.setColumnVisible('location', true) // shows location column
- }
- function onCellValueChanged() {
- alert('Edited!');
- // Here is where functionality would go to save
- // the rows to the database in AWS
- console.log("Cell edited");
- // How to get a row's data using the gridOptions api and the rowNode
- //var rowNode = gridOptions.api.getRowNode('1');
- //console.log(rowNode.data);
- rowNode = JSON.stringify(gridOptions.api.getRowNode('1'));
- localStorage.setItem('RowData', rowNode);
- }
- function exportCSV(){
- var exporto = gridOptions.api.getDataAsCsv();
- console.log(exporto);
- }
- // NOTHING BELOW THIS LINE IS WORKING AND I DONT KNOW WHY
- function upload(albumName) {
- var files = "duck";//document.getElementById("photoupload").files;
- if (!files.length) {
- return alert("Please choose a file to upload first.");
- }
- var file = files[0];
- var fileName = file.name;
- var albumPhotosKey = encodeURIComponent(albumName) + "//";
- var photoKey = albumPhotosKey + fileName;
- // Use S3 ManagedUpload class as it supports multipart uploads
- var upload = new AWS.S3.ManagedUpload({
- params: {
- Bucket: bucketName,
- Key: photoKey,
- Body: file,
- ACL: "public-read"
- }
- });
- var promise = upload.promise();
- promise.then(
- function(data) {
- alert("Successfully uploaded photo.");
- viewAlbum(albumName);
- },
- function(err) {
- return alert("There was an error uploading your photo: ", err.message);
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement