This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(vm-logs): log files * feat(vm-logs): log files * code style
- Loading branch information
Vladimir Shakhov
authored
Oct 19, 2018
1 parent
2fa5125
commit 6953691
Showing
21 changed files
with
624 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface LoadVmLogFilesRequestParams { | ||
id: string; | ||
startdate?: string; | ||
enddate?: string; | ||
page?: number; | ||
pagesize?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface VmLogFile { | ||
file: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createSelector } from '@ngrx/store'; | ||
import * as fromVMs from '../../../reducers/vm/redux/vm.reducers'; | ||
import { filterSelectedAccountIds, filterSelectedVmId } from '../vm-logs-vm.reducers'; | ||
import * as fromAccounts from '../../../reducers/accounts/redux/accounts.reducers'; | ||
|
||
export const selectFilteredVMs = createSelector( | ||
fromVMs.selectAll, | ||
filterSelectedAccountIds, | ||
filterSelectedVmId, | ||
fromAccounts.selectAll, | ||
( | ||
vms, | ||
selectedAccountIds, | ||
selectedVmId, | ||
accounts | ||
) => { | ||
const selectedAccounts = accounts.filter( | ||
account => selectedAccountIds.find(id => id === account.id)); | ||
const accountsMap = selectedAccounts.reduce((m, i) => ({ ...m, [i.name]: i }), {}); | ||
const domainsMap = selectedAccounts.reduce((m, i) => ({ ...m, [i.domainid]: i }), {}); | ||
|
||
const selectedAccountIdsFilter = vm => !selectedAccountIds.length || | ||
(accountsMap[vm.account] && domainsMap[vm.domainid]); | ||
|
||
const selectedVm = vms.find(vm => vm.id === selectedVmId); | ||
const filteredVms = vms.filter(vm => selectedAccountIdsFilter(vm)); | ||
|
||
if (!filteredVms.find(vm => vm.id === selectedVmId) && selectedVm) { | ||
return filteredVms.concat(selectedVm); | ||
} | ||
|
||
return filteredVms; | ||
} | ||
); |
10 changes: 10 additions & 0 deletions
10
src/app/vm-logs/redux/selectors/loadVmLogFilesRequestParams.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createSelector } from '@ngrx/store'; | ||
import { filterSelectedVmId } from '../vm-logs-vm.reducers'; | ||
import { LoadVmLogFilesRequestParams } from '../../models/load-vm-log-files-request-params'; | ||
|
||
export const loadVmLogFilesRequestParams = createSelector( | ||
filterSelectedVmId, | ||
(id): LoadVmLogFilesRequestParams => ({ | ||
id | ||
}) | ||
); |
77 changes: 77 additions & 0 deletions
77
src/app/vm-logs/redux/selectors/loadVmLogsRequestParams.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { loadVmLogsRequestParams } from './loadVmLogsRequestParams.selector'; | ||
import moment = require('moment'); | ||
|
||
|
||
describe('loadVmLogsRequestParams selector', () => { | ||
const date = moment(0); | ||
|
||
beforeAll(() => { | ||
jasmine.clock().mockDate(date.toDate()); | ||
}); | ||
|
||
it('should select load logs request params without keywords', () => { | ||
const id = 'test-id'; | ||
const keywords = []; | ||
|
||
const params = loadVmLogsRequestParams.projector( | ||
id, | ||
keywords | ||
); | ||
|
||
expect(params).toEqual({ | ||
id, | ||
startDate: '1970-01-01T00:00:00.000', | ||
endDate: '1970-01-01T00:00:00.000', | ||
sort: 'timestamp' | ||
}) | ||
}); | ||
|
||
it('should select load logs request params with keywords', () => { | ||
const id = 'test-id'; | ||
const keywords = [ | ||
{ text: 'test-keyword1' }, | ||
{ text: 'test-keyword2' } | ||
]; | ||
|
||
const params = loadVmLogsRequestParams.projector( | ||
id, | ||
keywords | ||
); | ||
|
||
expect(params).toEqual({ | ||
id, | ||
keywords: 'test-keyword1,test-keyword2', | ||
startDate: '1970-01-01T00:00:00.000', | ||
endDate: '1970-01-01T00:00:00.000', | ||
sort: 'timestamp' | ||
}); | ||
}); | ||
|
||
const defaultId = 'test-id'; | ||
const defaultDate = '1970-01-01T00:00:00.000'; | ||
const defaultSort = 'timestamp'; | ||
const defaultRequestParams = { | ||
id: defaultId, | ||
startDate: defaultDate, | ||
endDate: defaultDate, | ||
sort: defaultSort | ||
}; | ||
|
||
it('should set sort: -timestamp if newest first = true', () => { | ||
const id = 'test-id'; | ||
|
||
const params = loadVmLogsRequestParams.projector( | ||
id, | ||
[], | ||
date, | ||
date, | ||
'', | ||
true | ||
); | ||
|
||
expect(params).toEqual({ | ||
...defaultRequestParams, | ||
sort: '-timestamp' | ||
}); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
src/app/vm-logs/redux/selectors/loadVmLogsRequestParams.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createSelector } from '@ngrx/store'; | ||
import { filterSelectedVmId } from '../vm-logs-vm.reducers'; | ||
import { LoadVmLogsRequestParams } from '../../models/load-vm-logs-request-params'; | ||
import { | ||
filterEndDate, | ||
filterKeywords, | ||
filterNewestFirst, | ||
filterSelectedLogFile, | ||
filterStartDate | ||
} from '../vm-logs.reducers'; | ||
import moment = require('moment'); | ||
import * as pickBy from 'lodash/pickBy'; | ||
|
||
|
||
export const loadVmLogsRequestParams = createSelector( | ||
filterSelectedVmId, | ||
filterKeywords, | ||
filterStartDate, | ||
filterEndDate, | ||
filterSelectedLogFile, | ||
filterNewestFirst, | ||
(id, keywords, startDate, endDate, logFile, newestFirst): LoadVmLogsRequestParams => { | ||
const fields = { | ||
id, | ||
keywords: keywords.map(keyword => keyword.text).join(','), | ||
startDate: moment(startDate).toISOString().slice(0, -1), | ||
endDate: moment(endDate).toISOString().slice(0, -1), | ||
sort: newestFirst ? '-timestamp' : 'timestamp', | ||
logFile, | ||
}; | ||
|
||
return pickBy(fields, Boolean); | ||
} | ||
); | ||
|
Oops, something went wrong.