Angularjs Example: Sonar in Project Usage language Map (Coffeescript edition)

Source: Internet
Author: User
Tags getcolor reset sort

About Sonarlanguage is what dongdong, here is not described, if you are interested in it, please go to the previous essay open Source: angularjs example--sonar Project use language map. Here is a recent practice version of learning Coffeescript.

Coffeescript is a concise, JavaScript-based preprocessor language that can be statically compiled into JavaScript, which is primarily influenced by Ruby and Python and is now used for many rails and node projects. Coffeescript is not a hyper-set of JavaScript, nor is it a complete substitute. Coffeescript is a little bit:

Less, more compact, and clearer code

By avoiding and changing the use of bad parts of JavaScript, leaving only the essence, the code to reduce the error rate, easier to maintain

Best practices in JavaScript are adopted in many common patterns implementations

The JavaScript code generated by Coffeescript can be completely detected by JSLint

Many do not want to say so much, here is mainly a brief introduction, Coffeescript's LIANBI example.

The code is as follows:

App = Angular.module (' app ', []). Value ("$host", "http://nemo.sonarsource.org"). Facto    
         
        Ry ("$requestUrl", ($host)-> "#{$host}/api/resources"). Factory ("$dynamicColor", ($host)->    
         
               [R,g,b] = [10,10,0] {getcolor:->
         
          [R,g,b] = [(r+100), (g+400), (b +)] "##{(r + 256 * g + 65536 * b). toString 16}"    
         
        , Reset:-> [r,g,b] = [10,10,0]    
         
    };    
         
               ). directive (' ChartData ',-> Drawchart = (elementid, data)-> Chart = new Amcharts.ampiechart () Chart.dataprovider = Data Char T.titlefield = "name" Chart.valuefield = "Percentage" Chart.colorfieLD = "COLOR" chart.labelsenabled = False Chart.pulloutradius = 0  Chart.depth3d = Chart.angle = Legend = new Amcharts.amlegend () Legend.makertype = "Square" legend.align    
         
               = "Center" chart.addlegend legend Chart.write ElementID    

            Chart (scope, element, attr)-> scope.already.push (-> data = SC    
         
                     Ope. $eval (Attr.chartdata);    
         
                  Drawchart (element[0].id, data);    
         
    If element[0].id) ($scope, $window, $http, $requestUrl, $dynamicColor)->    
      $scope. already = [] $window. Angularjsonpcallback = (data)->   
         @data = Data Getobjectbykey = (MSR, key)-> m in M SR when M.key = = key $scope. Gridsource = $scope. Projects = Data Ready = (q ueues)-> Angular.foreach (queues, (q)-> Q ()) Ready $scope. Already $scope.    
         
         Getlanguagechartdata =-> data = _.groupby $scope. Projects, (project)-> Project.lang    
         
                      $dynamicColor. Reset () ChartData = _.map (data, (array, key)->    
         
                      "Name": Key "Percentage": Array.Length,    

    "Color": $dynamicColor. GetColor ()) _.sortby (ChartData, (num)-> num.percentage)    
         
            $scope. Search =-> Source = [] If not this.searchname Source = @projects   
         
        else Source = _.filter @projects, (p)-> P.name.tolowercase (). IndexOf $scope. Searchname.tolowercase ()!=-1 Source = _.sortby (source, p) -> p[$scope. Sortcondition.key].tolowercase ()) if @sortCondition and @sortCondition. Key Source.rev    
         
    Erse () if @sortCondition. Sort and not @sortCondition. sort[$scope. Sortcondition.key] @gridSource = Source $scope. Sort = (name)-> @sortCondition? = {} @sortCondition. s ORT = {} @sortCondition. Key = Name @sortCondition. sort[name] = not @sortCondi    

    Tion.sort[name] @search (); $scope. init =-> $http. Jsonp "#{$requestUrl}?callback=angularjsonpcallback" App.controller "repo RT ", the

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.