· 7 years ago · May 22, 2018, 12:54 PM
1
2 $scope.uploadBoolean = true;
3
4 $scope.showUploadDiv = function () {
5 $scope.uploadBoolean = true;
6 $scope.albumsBoolean = false;
7 $scope.photosBoolean = false;
8 var logOptions = { "logMessage" : "Opening Upload Modal in Comments Reply"
9 , "http_url" : $state.current.url , "http_request_params" : "",
10 "http_request_type" : "", "http_response" : "", "time" : moment(), "user_id" : ""}
11 monitoringService.storeLog(logOptions);
12 };
13
14
15 $scope.showAlbumsDiv = function () {
16 $scope.albumsBoolean = true;
17 $scope.uploadBoolean = false;
18 $scope.photosBoolean = false;);
19
20 };
21
22 $scope.showPhotosDiv = function () {
23 $scope.photosBoolean = true;
24 $scope.albumsBoolean = false;
25 $scope.uploadBoolean = false;
26
27 };
28
29
30
31 $scope.selectedAlbumChange = function (album) {
32 console.log(album,"chnggg")
33 $scope.selectedAlbum = album;
34
35 }
36
37 var logOptions = {}
38 logOptions["logMessage"] = "Getting Albums in Comments Reply";
39 var params = {}
40 params["service_name"] = "socialPosting";
41 socialHub_httpSerivce.get('albums/get_albums' , params, logOptions).then(function(result){
42
43 console.log(result);
44 $scope.albums = result;
45
46 },function(error){
47
48 });
49
50
51 $scope.add_album=function(){
52 if($scope.albumName != ""){
53 console.log($scope.albumName)
54
55 var params={
56 album_name: $scope.albumName
57 };
58
59 var logOptions = {}
60 logOptions["logMessage"] = "Adding Album in Twitter Reply" ;
61 params["service_name"] = "socialPosting";
62 socialHub_httpSerivce.post('albums/create_album' , params, logOptions).then(function(result){
63
64 if(result == "album exist before"){
65 swal("Album Exists before");
66 }else{
67 $scope.albums.push(result);
68 swal("Done");
69 }
70
71 },function(error){
72
73 });
74 }else{
75 swal("Please choose album name");
76 }
77
78 };
79
80
81
82 $scope.creds = {
83 bucket: 'imagesbucket2',
84 access_key: 'AKIAJC73J6XBJ26Z2LCA',
85 secret_key: '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'
86 }
87
88
89
90 $scope.prog = 0;
91
92 $scope.upload = function() {
93 // Configure The S3 Object
94 console.log("uploaaaaaaaaad");
95 var logOptions = { "logMessage" : "Uploading File in Twitter Reply"
96 , "http_url" : $state.current.url , "http_request_params" : "",
97 "http_request_type" : "", "http_response" : "", "time" : moment(), "user_id" : ""}
98 monitoringService.storeLog(logOptions);
99
100 if($scope.myFile){
101
102 console.log("fileeeeeeeeee");
103 $scope.mediaName = $scope.myFile.name;
104
105 $scope.myFile = $scope.myFile;
106
107 }
108
109
110 AWS.config.update({ accessKeyId: $scope.creds.access_key, secretAccessKey: $scope.creds.secret_key });
111 // AWS.config.region = 'us-standard';
112 var bucket = new AWS.S3({ params: { Bucket: $scope.creds.bucket } });
113
114 if($scope.myFile) {
115 var params = { Key: $scope.myFile.name, ContentType: $scope.myFile.type, Body: $scope.myFile, ServerSideEncryption: 'AES256' , ACL: 'public-read-write'};
116
117 console.log(params,"prrrrrrrrrrrrrrrr");
118
119 bucket.putObject(params, function(err, data) {
120 if(err) {
121 // There Was An Error With Your S3 Config
122 console.log(err.message);
123 return false;
124 }
125 else {
126 // Success!
127 console.log('Upload Done');
128
129
130 $timeout(function() {
131
132 $scope.chosen_photo_url= 'https://s3.amazonaws.com/imagesbucket2/'+$scope.myFile.name;
133
134 // $scope.reply_text = $scope.chosen_photo_url;
135
136 var params={
137 album_id : $scope.selectedAlbum ,
138 media_url: $scope.chosen_photo_url,
139 media_name: $scope.myFile.name
140 };
141
142 if($scope.myFile.name) {
143
144 var logOptions = {}
145 logOptions["logMessage"] = "Adding Media To Album in Comments Reply";
146 params["service_name"] = "socialPosting";
147 socialHub_httpSerivce.post('albums/add_media_to_album' , params, logOptions).then(function(result){
148
149 console.log(result);
150 swal("Photo uploaded successfully ");
151
152 },function(error){
153
154 });
155
156 }
157
158
159 }, 0);
160
161 }
162 })
163 .on('httpUploadProgress',function(progress) {
164 // Log Progress Information
165 console.log($('.progress-bar'));
166 $scope.prog = Math.round(progress.loaded / progress.total * 100);
167 $('.progress-bar').css('width', $scope.prog +'%');
168 $('.progress-bar').text($scope.prog +'%');
169 console.log( $scope.prog + '% done');
170
171 });
172 }
173 else {
174 // No File Selected
175 swal('No File Selected');
176 }
177 };
178
179
180
181 $scope.photos = $scope.photos ;
182 console.log($scope.photos,"photoooos");
183
184
185
186 $scope.photo_click=function(photo_url,media_name){
187
188 console.log("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
189 console.log(photo_url)
190
191
192 $timeout(function() {
193 $scope.chosen_photo_url = photo_url;
194
195// $scope.reply_text = photo_url;
196
197 }, 0);
198
199
200
201
202 $scope.mediaName = media_name;
203
204 };
205
206
207 $scope.albumClick= function(album_ids){
208
209 console.log("album id is "+ album_ids);
210
211 var params={
212 album_id:album_ids
213 };
214 var logOptions = {};
215 logOptions["logMessage"] = "Getting Album Media in Comments Reply";
216 params["service_name"] = "socialPosting";
217
218 socialHub_httpSerivce.get('albums/get_media_for_album' , params, logOptions).then(function(result){
219
220 console.log(result);
221 $scope.photos = result;
222 $timeout(function() {
223 document.getElementById("photosTabid").click();
224 }, 0);
225
226
227 },function(error){
228 swal("something went wrong");
229 });
230
231 };