Snippets Collections
 <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min-date="minDate" max-date="'2022-06-22'" datepicker-options="dateOptions" ng-required="true" close-text="Close"
          />
<!DOCTYPE html>
<html>
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body ng-app="_APPNAME_" ng-controller="_CONTROLLERNAME_">

	<h2>_APPNAME_</h2>

	
	<input type="text" ng-model="value" />
	

	<p>
		<button ng-click="save()">Save</button>
		<button ng-click="clear()">Clear</button>
	</p>

	<p>Saved Value: <span ng-bind="savedValueFunction()"></span></p>



	<script>
	var app = angular.module("_APPNAME_", []); 
	app.controller("_CONTROLLERNAME_", function($scope) {
		
		$scope.value = "";
		$scope.savedValue = "";
		
		$scope.savedValueFunction = function() {
			return $scope.savedValue;
		};
		$scope.clear = function() {
			$scope.value = "";
      $scope.savedValue="";
		};
		$scope.save = function() {
			alert("Saved");
      $scope.savedValue=$scope.value;
		};
	});
	</script>



</body>
</html>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Caching;
using System.Web;

namespace Common
{
    public static class CacheHelper
    {
        public static void AddOrUpdate(string key, object value, int expiresinhours)
        {
            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Cache[key] != null)
                {
                    HttpContext.Current.Cache[key] = value;
                }
                else
                {
                    HttpContext.Current.Cache.Add(key, value, null, DateTime.Now.AddHours(expiresinhours), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                }
            }
            else if (MemoryCache.Default != null)
            {
                if (MemoryCache.Default[key] != null)
                {
                    MemoryCache.Default[key] = value;
                }
                else
                {
                    CacheItemPolicy policy = new CacheItemPolicy();
                    policy.AbsoluteExpiration = DateTime.Now.AddHours(expiresinhours);
                    MemoryCache.Default.Set(key, value, policy);
                }
            }
        }

        public static object Get(string key)
        {
            ObjectCache cache = MemoryCache.Default;
    
            if (HttpContext.Current!= null && HttpContext.Current.Cache[key] != null)
            {
                return HttpContext.Current.Cache[key];
            }
            else if (MemoryCache.Default != null && MemoryCache.Default[key] != null)
            {
                return MemoryCache.Default[key];
            }

            return null;
        }

        public static void DeleteCacheThatContains(string value)
        {
            if (HttpContext.Current != null)
            {
                List<string> keys = new List<string>();

                // retrieve application Cache enumerator
                IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();

                // copy all keys that currently exist in Cache
                while (enumerator.MoveNext())
                {
                    if (enumerator.Key.ToString().Contains(value))
                        keys.Add(enumerator.Key.ToString());
                }

                // delete every key from cache
                for (int i = 0; i < keys.Count; i++)
                {
                    HttpContext.Current.Cache.Remove(keys[i]);
                }
            }
        }


        public static void ClearAllCache()
        {
            if (HttpContext.Current != null)
            {
                List<string> keys = new List<string>();

                // retrieve application Cache enumerator
                IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();

                // copy all keys that currently exist in Cache
                while (enumerator.MoveNext())
                {
                    keys.Add(enumerator.Key.ToString());
                }

                // delete every key from cache
                for (int i = 0; i < keys.Count; i++)
                {
                    HttpContext.Current.Cache.Remove(keys[i]);
                }
            }
        }
    }
}
distinct: function (list, identifierFunc) {

                let result = [];

                const map = new Map();

                list.forEach(item => {
                    let id = identifierFunc(item).toUpperCase();
                    if (!map.has(id)) {
                        map.set(id, true);

                        result.push(item);
                    }
                });

                return result;
            }
JSONToCSVConvertor: function (JSONData, FileName, ShowLabel) {
                //If JSONData is not an object then JSON.parse will parse the JSON string in an Object
                var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;

                var CSV = '';
                //Set Report title in first row or line

                //CSV += ReportTitle + '\r\n\n';

                //This condition will generate the Label/Header
                if (ShowLabel) {
                    var row = "";

                    //This loop will extract the label from 1st index of on array
                    for (var index in arrData[0]) {

                        //Now convert each value to string and comma-seprated
                        row += index + ',';
                    }

                    row = row.slice(0, -1);

                    //append Label row with line break
                    CSV += row + '\r\n';
                }

                //1st loop is to extract each row
                for (var i = 0; i < arrData.length; i++) {
                    var row = "";

                    //2nd loop will extract each column and convert it in string comma-seprated
                    for (var index in arrData[i]) {
                        row += '"' + arrData[i][index] + '",';
                    }

                    row.slice(0, row.length - 1);

                    //add a line break after each row
                    CSV += row + '\r\n';
                }

                if (CSV == '') {
                    alert("Invalid data");
                    return;
                }

                //Generate a file name
                var fileName = FileName;
                //this will remove the blank-spaces from the title and replace it with an underscore
                //fileName += ReportTitle.replace(/ /g, "_");

                //Initialize file format you want csv or xls
                var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);

                // Now the little tricky part.
                // you can use either>> window.open(uri);
                // but this will not work in some browsers
                // or you will not get the correct file extension    

                //this trick will generate a temp <a /> tag
                var link = document.createElement("a");
                link.href = uri;

                //set the visibility hidden so it will not effect on your web-layout
                link.style = "visibility:hidden";
                link.download = fileName + ".csv";

                //this part will append the anchor tag and remove it after automatic click
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
buildComboDataSource: function (endpoint, sortField, pageSize) {
                return {
                    type: "odata-v4",
                    transport: {
                        read: {
                            url: this.odata.url() + endpoint,
                            dataType: "json",
                            xhrFields: {
                                withCredentials: true //needed for windows auth
                            }
                        }
                    },
                    schema: {
                        total: function (data) {
                            return data["@odata.count"];
                        }
                    },
                    pageSize: pageSize,
                    serverPaging: pageSize > 0 ? true : false,
                    serverFiltering: true,
                    serverSorting: true,
                    sort: {
                        field: sortField,
                        dir: "asc"
                    }
                };
            }
star

Mon Oct 11 2021 12:18:12 GMT+0000 (UTC) http://embed.plnkr.co/OVh5h7GJYkthVwCUkZwJ/

#javascript #angularjs
star

Thu Sep 23 2021 14:21:49 GMT+0000 (UTC)

#javascript #angularjs
star

Wed Sep 22 2021 14:25:24 GMT+0000 (UTC)

#javascript #angularjs
star

Wed Sep 22 2021 13:54:50 GMT+0000 (UTC)

#javascript #angularjs
star

Wed Sep 22 2021 13:53:03 GMT+0000 (UTC)

#javascript #angularjs

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension