user picker

This commit is contained in:
2020-09-16 10:51:26 +02:00
parent c12149aee4
commit 9841e2eece
4 changed files with 137 additions and 21 deletions
+19 -7
View File
@@ -36,12 +36,19 @@ namespace zero.Core.Api
/// <inheritdoc />
public async Task<IList<IUser>> GetAll(string appId = null)
public async Task<Dictionary<string, IUser>> GetByIds(params string[] ids)
{
return await GetByIds<IUser>(ids);
}
/// <inheritdoc />
public async Task<IList<IUser>> GetAll()
{
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
{
return await session.Query<IUser>()
.Scope(appId)
.Scope(Scope)
.OrderByDescending(x => x.CreatedDate)
.ToListAsync();
}
@@ -49,14 +56,14 @@ namespace zero.Core.Api
/// <inheritdoc />
public async Task<ListResult<IUser>> GetByQuery(ListQuery<IUser> query, string appId = null)
public async Task<ListResult<IUser>> GetByQuery(ListQuery<IUser> query)
{
query.SearchSelector = user => user.Name;
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
{
return await session.Query<IUser>()
.Scope(appId)
.Scope(Scope)
.ToQueriedListAsync(query);
}
}
@@ -160,17 +167,22 @@ namespace zero.Core.Api
/// <summary>
/// Find user by email
/// </summary>
Task<IUser> GetUserByEmail(string email);
Task<IUser> GetUserByEmail(string email);
/// <summary>
/// Get users by ids
/// </summary>
Task<Dictionary<string, IUser>> GetByIds(params string[] ids);
/// <summary>
/// Get all users for the selected application
/// </summary>
Task<IList<IUser>> GetAll(string appId = null);
Task<IList<IUser>> GetAll();
/// <summary>
/// Get all available users (with query)
/// </summary>
Task<ListResult<IUser>> GetByQuery(ListQuery<IUser> query, string appId = null);
Task<ListResult<IUser>> GetByQuery(ListQuery<IUser> query);
/// <summary>
/// Creates or updates a user
@@ -0,0 +1,78 @@
<template>
<div class="ui-userpicker" :class="{'is-disabled': disabled }">
<ui-pick :config="pickerConfig" :value="value" @input="onChange" :disabled="disabled" />
</div>
</template>
<script>
import UsersApi from 'zero/resources/users.js'
import { extend as _extend } from 'deps/underscore'
export default {
name: 'uiUserpicker',
props: {
value: {
type: [String, Array],
default: null
},
limit: {
type: Number,
default: 1
},
disabled: {
type: Boolean,
default: false
},
options: {
type: Object,
default: () => { }
}
},
data: () => ({
previews: [],
pickerConfig: {}
}),
created()
{
this.pickerConfig = _extend({
scope: 'user',
items: UsersApi.getForPicker,
previews: UsersApi.getPreviews,
limit: this.limit,
multiple: this.limit > 1,
preview: {
enabled: true,
iconAsImage: true
}
}, this.options);
},
methods: {
onChange(value)
{
this.$emit('input', value);
}
}
}
</script>
<style lang="scss">
.ui-userpicker
{
.ui-select-button-icon.is-image, .ui-select-button-icon
{
padding: 0;
border-radius: 50px;
img
{
border-radius: 50px;
}
}
}
</style>
+19 -14
View File
@@ -1,47 +1,52 @@
import Axios from 'axios';
import AuthApi from 'zero/services/auth';
const base = 'users/';
export default {
// get user by id
getById(id)
{
return Axios.get('users/getById', { params: { id } }).then(res => Promise.resolve(res.data));
return Axios.get(base + 'getById', { params: { id } }).then(res => Promise.resolve(res.data));
},
// get all users
getAll(query)
{
return Axios.get('users/getAll', { params: query }).then(res => Promise.resolve(res.data));
return Axios.get(base + 'getAll', { params: query }).then(res => Promise.resolve(res.data));
},
getPreviews(ids)
{
return Axios.get(base + 'getPreviews', { params: { ids } }).then(res => Promise.resolve(res.data));
},
getForPicker()
{
return Axios.get(base + 'getForPicker').then(res => Promise.resolve(res.data));
},
// save a user
save(model)
{
return Axios.post('users/save', model).then(res => Promise.resolve(res.data));
return Axios.post(base + 'save', model).then(res => Promise.resolve(res.data));
},
// deletes a user
delete(id)
{
return Axios.delete('users/delete', { params: { id } }).then(res => Promise.resolve(res.data));
return Axios.delete(base + 'delete', { params: { id } }).then(res => Promise.resolve(res.data));
},
// change password
updatePassword(model)
{
return Axios.post('users/updatePassword', model).then(res => Promise.resolve(res.data));
return Axios.post(base + 'updatePassword', model).then(res => Promise.resolve(res.data));
},
// disable user
disable(model)
{
return Axios.post('users/disable', model).then(res => Promise.resolve(res.data));
return Axios.post(base + 'disable', model).then(res => Promise.resolve(res.data));
},
// enable user
enable(model)
{
return Axios.post('users/enable', model).then(res => Promise.resolve(res.data));
return Axios.post(base + 'enable', model).then(res => Promise.resolve(res.data));
}
};
+21
View File
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
@@ -32,6 +34,25 @@ namespace zero.Web.Controllers
public IActionResult GetAllPermissions() => Json(PermissionsApi.GetAll());
public async Task<IActionResult> GetForPicker() => Json((await Api.GetAll()).Select(x => new SelectModel()
{
Id = x.Id,
Name = x.Name,
IsActive = x.IsActive
}));
public async Task<IActionResult> GetPreviews(List<string> ids)
{
return JsonPreviews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
{
Id = item.Id,
Icon = item.AvatarId,
Name = item.Name
});
}
[ZeroAuthorize]
public async Task<IActionResult> UpdatePassword([FromBody] UserPasswordEditModel model)
{