RootApp = angular.module('RootApp', ['angularMoment','ui.router',"ngMask","tooltips",'angular.chosen']); RootApp.controller('RootCtr', function ($rootScope, $scope, $http, $timeout, $state,$compile, $location,moment,$interval) { $rootScope.server = "/api"; }); RootApp.directive('rate', function () { return { restrict: 'E', scope: { ngModel: '=', ngValue: '=', label: '=' }, template: `
`, controller: function ($rootScope, $scope, $element) { if ($scope.ngValue) $scope.ngModel = angular.copy($scope.ngValue) $scope.change = (e)=>{ $scope.ngModel=e; } console.log($element); } } }); RootApp.directive('info', function () { return { restrict: 'E', scope: { text: '='}, template: `{{text}} ` } }); RootApp.directive('file', function () { return { restrict: 'E', scope: { src: '=' }, template: ``, controller: function ($scope, $element) { $scope.src?.split(",").forEach(fileId => { const size = $element.attr('size') || 20; $($element[0]).append(` File Thumbnail `); }); } } }); RootApp.directive('fileChange', [function () { return { restrict: 'A', scope: { fileChange: '&' }, link: function (scope, element) { element.on('change', function (event) { scope.$apply(function () { scope.fileChange({ $files: event.target.files }); }); }); } }; }]); RootApp.directive('fileInput', ['$http', '$timeout', function ($http, $timeout) { return { restrict: 'E', template: `
ჩააგდეთ ფაილები აქ (Image, PDF, Excel) ან დააწკაპუნეთ ასატვირთად
Preview
{{file.name | limitTo: 10}}{{file.name.length > 10 ? '...' : ''}}
ატვირთულია
{{file.uploadProgress}}%
{{file.errorMessage}}
`, scope: { ngModel: '=', }, controller: ['$scope', '$http', '$element', '$attrs', function ($scope, $http, $element) { $scope.files = []; $scope.isDragOver = false; $scope.ngModel = ''; // დამხმარე ფუნქცია იკონის ტიპის დასადგენად function getFileIcon(filename) { const ext = filename.split('.').pop().toLowerCase(); switch (ext) { case 'pdf': return 'far fa-file-pdf text-danger'; // წითელი PDF იკონი case 'xls': case 'xlsx': return 'far fa-file-excel text-success'; // მწვანე Excel იკონი case 'doc': case 'docx': return 'far fa-file-word text-primary'; default: return 'far fa-file'; // ზოგადი ფაილის იკონი } } function resizeImage(file, callback) { const MAX_WIDTH = 1024; const MAX_HEIGHT = 1024; const img = new Image(); const reader = new FileReader(); reader.onload = function (e) { img.src = e.target.result; img.onload = function () { let width = img.width; let height = img.height; if (width > MAX_WIDTH || height > MAX_HEIGHT) { if (width > height) { height = Math.round((MAX_WIDTH / width) * height); width = MAX_WIDTH; } else { width = Math.round((MAX_HEIGHT / height) * width); height = MAX_HEIGHT; } } const canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, width, height); canvas.toBlob(function (blob) { const resizedFile = new File([blob], file.name, { type: file.type }); callback(resizedFile); }, file.type); }; }; reader.readAsDataURL(file); } $scope.openFileDialog = function () { $element.find('input[type="file"]').click(); }; $scope.onFileSelect = function (files) { angular.forEach(files, function (file) { const isImage = file.type.startsWith('image/'); if (isImage) { resizeImage(file, function (resizedFile) { const reader = new FileReader(); reader.onload = function (e) { $timeout(function () { addFileToQueue(resizedFile, e.target.result, true); }); }; reader.readAsDataURL(resizedFile); }); } else { // PDF ან Excel-ის შემთხვევაში პრევიუ არ გვჭირდება, მხოლოდ იკონი $timeout(function () { addFileToQueue(file, null, false); }); } }); }; function addFileToQueue(file, preview, isImage) { file.preview = preview; file.isImage = isImage; file.iconClass = getFileIcon(file.name); file.isUploading = false; file.uploadProgress = 0; file.errorMessage = ''; file.unic = false; $scope.files.push(file); } $scope.allUploaded = function () { return $scope.files.every(function (file) { return file.unic || file.isUploading; }); }; $scope.uploadFile = function (file) { file.isUploading = true; const formData = new FormData(); formData.append('file', file); let url = '/api/file/upload'; if(file.isImage) url= '/api/file/upload_code'; $http.post(url, formData, { headers: { 'Content-Type': undefined }, transformRequest: angular.identity, uploadEventHandlers: { progress: function (e) { if (e.lengthComputable) { $timeout(function () { file.uploadProgress = Math.round((e.loaded / e.total) * 100); }); } } } }).then(function (response) { file.isUploading = false; if (response.data && response.data.unic) { file.unic = response.data.unic; $scope.updateNgModel(); } }).catch(function () { file.isUploading = false; file.uploadProgress = 0; file.errorMessage = 'ატვირთვა ვერ მოხერხდა.'; }); }; $scope.uploadAll = function () { angular.forEach($scope.files, function (file) { if (!file.unic && !file.isUploading) { $scope.uploadFile(file); } }); }; $scope.removeFile = function (file) { if (file.isUploading) { alert('მიმდინარეობს ატვირთვა, წაშლა შეუძლებელია.'); return; } const index = $scope.files.indexOf(file); if (index > -1) { $scope.files.splice(index, 1); $scope.updateNgModel(); } }; $scope.updateNgModel = function () { const unicValues = $scope.files .filter(file => file.unic) .map(file => file.unic); $scope.ngModel = unicValues.join(','); }; const dropzone = $element[0].querySelector('.dropzone'); dropzone.addEventListener('dragover', function (event) { event.preventDefault(); $timeout(function () { $scope.isDragOver = true; }); }); dropzone.addEventListener('dragleave', function (event) { event.preventDefault(); $timeout(function () { $scope.isDragOver = false; }); }); dropzone.addEventListener('drop', function (event) { event.preventDefault(); const files = event.dataTransfer.files; $scope.isDragOver = false; $scope.onFileSelect(files); }); }] }; }]); RootApp.directive('chart', function () { return {scope: { data: '=', chart:'=' }, template: '.', controller: function ($rootScope, $scope, $element,$timeout) { $timeout(()=>{ $scope.chart.chart = $scope.chart.chart ?? {}; $scope.chart.chart.renderTo=$element[0]; new Highcharts.Chart($scope.chart); },300) } }}); RootApp.run(function (amMoment) { amMoment.changeLocale('ka');}); RootApp.config(function ($stateProvider,$locationProvider,$urlRouterProvider) { $stateProvider .state("/login", { url : '/login', templateUrl: "/app/templates/login.php", controller: function ($scope,$rootScope,$http) { $scope.login=(u)=>{ $http.post($rootScope.server + "/login", u).then(function () { // $rootScope.data_loaded = false; Swal.fire("","თქვენ წარმატებით გაიარეთ ავტორიზაცია","success") setTimeout(()=>{ location.href=`/`; },200); },()=>{ Swal.fire("","მომხმარებელი არ მოიძებნა","error") }); } } }) .state("/", { url: '/', templateUrl: "/app/templates/main.php", controller: function ($state) { $state.go('/login'); }}) $urlRouterProvider.otherwise("/"); $locationProvider.html5Mode({ enabled: true, requireBase: false }); });