Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyMartynov committed Nov 19, 2015
0 parents commit a7e69c2
Show file tree
Hide file tree
Showing 44 changed files with 1,866 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin/
obj/
.vs/
node_modules/
**/wwwroot/lib/
project.lock.json
*.suo
*.*proj.user
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Developer Express Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '{build}'

environment:
DNX_VERSION: '1.0.0-rc1-final'

cache:
- '%USERPROFILE%\.dnx\runtimes -> appveyor.yml'
- '%USERPROFILE%\.dnx\packages -> appveyor.yml, **\project.json'
- node_modules

install:
- ps: iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))
- dnvm install %DNX_VERSION% -r clr
- npm install jshint

before_build:
- dnu restore --quiet
- powershell -File build\patch_version.ps1 %APPVEYOR_REPO_TAG_NAME%

build_script:
- msbuild net\DevExtreme.AspNet.Data.sln /v:q

test_script:
- node_modules\.bin\jshint js
- dnx -p net\DevExtreme.AspNet.Data.Tests test

after_test:
- dnu pack net\DevExtreme.AspNet.Data --configuration=Release --quiet

artifacts:
- path: net\DevExtreme.AspNet.Data\bin\Release\*.nupkg
8 changes: 8 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "devextreme-aspnet-data",
"description": "DevExtreme data layer extension for ASP.NET MVC",
"authors": [ "Developer Express Inc." ],
"license": "MIT",
"ignore": [ "build", "net", "appveyor.yml" ],
"main": [ "js/dx.aspnet.data.js" ]
}
14 changes: 14 additions & 0 deletions build/patch_version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
param ([string]$version)

If ($version -match '^([.\d]+)[\w-]*') {
$fullVersion = $matches[0]
$numericVersion = $matches[1]

Write-Host "Patching version: $numericVersion ($fullVersion)"

$assemblyFile = "$PSScriptRoot\..\net\DevExtreme.AspNet.Data\AssemblyInfo.cs"
$projectFile = "$PSScriptRoot\..\net\DevExtreme.AspNet.Data\project.json"

(Get-Content $assemblyFile) -replace '(AssemblyVersion.+?")[^"]+', "`${1}$numericVersion" | Set-Content $assemblyFile
(Get-Content $projectFile) -replace '("version":.+?")[^"]+', "`${1}$fullVersion" | Set-Content $projectFile
}
134 changes: 134 additions & 0 deletions js/dx.aspnet.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// https://github.com/DevExpress/DevExtreme.AspNet.Data
// Copyright (c) Developer Express Inc.

(function($, DX) {

function createStore(options) {
return new DX.data.CustomStore(createStoreConfig(options));
}

function createStoreConfig(options) {
var keyExpr = options.key,
loadUrl = options.loadUrl,
updateUrl = options.updateUrl,
insertUrl = options.insertUrl,
deleteUrl = options.deleteUrl,
onBeforeSend = options.onBeforeSend;

function send(operation, settings) {
if(onBeforeSend)
onBeforeSend(operation, settings);

return $.ajax(settings);
}

function filterByKey(keyValue) {
if(!$.isArray(keyExpr))
return [keyExpr, keyValue];

return $.map(keyExpr, function(i) {
return [[i, keyValue[i]]];
});
}

return {
key: keyExpr,

load: function(loadOptions) {
var d = new $.Deferred();

send("load", {
url: loadUrl,
data: loadOptionsToActionParams(loadOptions)
}).done(function(res) {
if("totalCount" in res)
d.resolve(res.data, { totalCount: res.totalCount });
else
d.resolve(res);
});

return d.promise();
},

totalCount: function(loadOptions) {
return send("load", {
url: loadUrl,
data: loadOptionsToActionParams(loadOptions, true)
});
},

byKey: keyExpr && function(key) {
var d = new $.Deferred();

send("load", {
url: loadUrl,
data: loadOptionsToActionParams({ filter: filterByKey(key) })
}).done(function(res) {
d.resolve(res[0]);
});

return d.promise();
},

update: updateUrl && function(key, values) {
return send("update", {
url: updateUrl,
type: options.updateMethod || "PUT",
data: {
key: serializeKey(key),
values: JSON.stringify(values)
}
});
},

insert: insertUrl && function(values) {
return send("insert", {
url: insertUrl,
type: options.insertMethod || "POST",
data: { values: JSON.stringify(values) }
});
},

remove: deleteUrl && function(key) {
return send("delete", {
url: deleteUrl,
type: options.deleteMethod || "DELETE",
data: { key: serializeKey(key) }
});
}

};
}

function loadOptionsToActionParams(options, isCountQuery) {
var result = {
requireTotalCount: options.requireTotalCount,
isCountQuery: isCountQuery,
skip: options.skip,
take: options.take,
};

if($.isArray(options.sort))
result.sort = JSON.stringify(options.sort);

if($.isArray(options.filter))
result.filter = JSON.stringify(options.filter);

return result;
}

function serializeKey(key) {
if(typeof key === "object")
return JSON.stringify(key);

return key;
}

$.extend(DX.data, {
AspNet: {
createStore: createStore,
createStoreConfig: createStoreConfig
}
});

})(jQuery, DevExpress);
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace DevExtreme.AspNet.Data.Tests {

public class DataSourceExpressionBuilderTests {
public void Build_SkipTake() {
var builder = new DataSourceExpressionBuilder<int> {
Skip = 111,
Take = 222
};

var expr = builder.Build(false);

Assert.Equal("data.Skip(111).Take(222)", expr.Body.ToString());
}

[Fact]
public void Build_Filter() {
var builder = new DataSourceExpressionBuilder<int> {
Filter = new object[] { "this", ">", 123 }
};

var expr = builder.Build(false);

Assert.Equal("data.Where(obj => (obj > 123))", expr.Body.ToString());
}

[Fact]
public void Build_CountQuery() {
var builder = new DataSourceExpressionBuilder<int> {
Skip = 111,
Take = 222,
Filter = new object[] { "this", 123 },
Sort = new[] {
new SortingInfo { Selector = "this" }
},
};

var expr = builder.Build(true);
var text = expr.ToString();

Assert.Contains("Where", text);
Assert.DoesNotContain("Skip", text);
Assert.DoesNotContain("Take", text);
Assert.DoesNotContain("OrderBy", text);
Assert.EndsWith(".Count()", text);
}

[Fact]
public void Build_Sorting() {
var builder = new DataSourceExpressionBuilder<Tuple<int, string>> {
Sort = new[] {
new SortingInfo {
Selector="Item1"
},
new SortingInfo {
Selector = "Item2",
Desc=true
}
}
};

var expr = builder.Build(false);
Assert.Equal("data.OrderBy(obj => obj.Item1).ThenByDescending(obj => obj.Item2)", expr.Body.ToString());
}
}

}
61 changes: 61 additions & 0 deletions net/DevExtreme.AspNet.Data.Tests/DataSourceLoaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace DevExtreme.AspNet.Data.Tests {

public class DataSourceLoaderTests {

[Fact]
public void TotalCount() {
var data = new[] { 1, 3, 2 };
var options = new DataSourceLoadOptions {
Filter = new object[] { "this", "<>", 2 },
Take = 1,
IsCountQuery = true
};

Assert.Equal(2, new DataSourceLoader().Load(data, options));
}

[Fact]
public void Load_NoRequireTotalCount() {
var data = new[] { 1, 3, 5, 2, 4 };
var options = new DataSourceLoadOptions {
Skip = 1,
Take = 2,
Filter = new object[] { "this", "<>", 2 },
Sort = new[] {
new SortingInfo { Selector = "this" }
},
RequireTotalCount = false
};

Assert.Equal(new[] { 3, 4 }, new DataSourceLoader().Load(data, options) as IEnumerable<int>);
}

[Fact]
public void Load_RequireTotalCount() {
var data = new[] { 1, 3, 5, 2, 4 };
var options = new DataSourceLoadOptions {
Skip = 1,
Take = 2,
Filter = new object[] { "this", "<>", 2 },
Sort = new[] {
new SortingInfo { Selector = "this" }
},
RequireTotalCount = true
};

var result = new DataSourceLoader().Load(data, options) as IDictionary;
Assert.NotNull(result);

Assert.Equal(4, result["totalCount"]);
Assert.Equal(new[] { 3, 4 }, result["data"] as IEnumerable<int>);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>85dc5135-d5f8-4404-ac2f-9029f2f73f6d</ProjectGuid>
<RootNamespace>DevExtreme.AspNet.Data.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading

0 comments on commit a7e69c2

Please sign in to comment.